From a9218ed5f007826942c972ea63b1dc473a8eb9b8 Mon Sep 17 00:00:00 2001 From: boojack Date: Sat, 11 Mar 2023 09:13:54 +0800 Subject: [PATCH] refactor: filter store (#1331) --- web/src/App.tsx | 10 +- web/src/components/AboutSiteDialog.tsx | 16 +++- web/src/components/Header.tsx | 7 +- web/src/components/HomeSidebar.tsx | 6 +- web/src/components/Memo.tsx | 16 ++-- web/src/components/MemoEditor.tsx | 14 +-- web/src/components/MemoFilter.tsx | 27 ++++-- web/src/components/MemoList.tsx | 12 +-- web/src/components/MobileHeader.tsx | 12 +-- web/src/components/SearchBar.tsx | 10 +- web/src/components/ShortcutList.tsx | 18 ++-- web/src/components/TagList.tsx | 14 +-- web/src/components/UsageHeatMap.tsx | 10 +- web/src/pages/Explore.tsx | 11 ++- web/src/pages/MemoDetail.tsx | 7 +- web/src/store/index.ts | 4 +- web/src/store/module/filter.ts | 77 ++++++++++++++++ web/src/store/module/index.ts | 2 +- web/src/store/module/location.ts | 122 ------------------------- web/src/store/module/user.ts | 2 +- web/src/store/reducer/filter.ts | 38 ++++++++ web/src/store/reducer/location.ts | 107 ---------------------- web/src/types/location.d.ts | 0 23 files changed, 215 insertions(+), 327 deletions(-) create mode 100644 web/src/store/module/filter.ts delete mode 100644 web/src/store/module/location.ts create mode 100644 web/src/store/reducer/filter.ts delete mode 100644 web/src/store/reducer/location.ts delete mode 100644 web/src/types/location.d.ts diff --git a/web/src/App.tsx b/web/src/App.tsx index b5065ef3..88e541f4 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -4,7 +4,7 @@ import { Toaster } from "react-hot-toast"; import { useTranslation } from "react-i18next"; import { RouterProvider } from "react-router-dom"; import router from "./router"; -import { useLocationStore, useGlobalStore } from "./store/module"; +import { useGlobalStore } from "./store/module"; import * as storage from "./helpers/storage"; import { getSystemColorScheme } from "./helpers/utils"; import Loading from "./pages/Loading"; @@ -12,17 +12,9 @@ import Loading from "./pages/Loading"; const App = () => { const { i18n } = useTranslation(); const globalStore = useGlobalStore(); - const locationStore = useLocationStore(); const { mode, setMode } = useColorScheme(); const { appearance, locale, systemStatus } = globalStore.state; - useEffect(() => { - locationStore.updateStateWithLocation(); - window.onpopstate = () => { - locationStore.updateStateWithLocation(); - }; - }, []); - useEffect(() => { const darkMediaQuery = window.matchMedia("(prefers-color-scheme: dark)"); const handleColorSchemeChange = (e: MediaQueryListEvent) => { diff --git a/web/src/components/AboutSiteDialog.tsx b/web/src/components/AboutSiteDialog.tsx index aff70d12..e68d1c1a 100644 --- a/web/src/components/AboutSiteDialog.tsx +++ b/web/src/components/AboutSiteDialog.tsx @@ -26,9 +26,9 @@ const AboutSiteDialog: React.FC = ({ destroy }: Props) => { -
+

{customizedProfile.description || "No description"}

-
+ - diff --git a/web/src/components/Header.tsx b/web/src/components/Header.tsx index 80955e44..268816e3 100644 --- a/web/src/components/Header.tsx +++ b/web/src/components/Header.tsx @@ -1,5 +1,5 @@ import { useEffect } from "react"; -import { NavLink } from "react-router-dom"; +import { NavLink, useLocation } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { useLayoutStore, useUserStore } from "../store/module"; import { resolution } from "../utils/layout"; @@ -12,6 +12,7 @@ import UserBanner from "./UserBanner"; const Header = () => { const { t } = useTranslation(); + const location = useLocation(); const userStore = useUserStore(); const layoutStore = useLayoutStore(); const showHeader = layoutStore.state.showHeader; @@ -27,7 +28,7 @@ const Header = () => { }; window.addEventListener("resize", handleWindowResize); handleWindowResize(); - }, []); + }, [location]); return (
{ onClick={() => layoutStore.setHeaderStatus(false)} >
diff --git a/web/src/components/HomeSidebar.tsx b/web/src/components/HomeSidebar.tsx index 2d8704d1..cd803c19 100644 --- a/web/src/components/HomeSidebar.tsx +++ b/web/src/components/HomeSidebar.tsx @@ -5,8 +5,10 @@ import ShortcutList from "./ShortcutList"; import TagList from "./TagList"; import SearchBar from "./SearchBar"; import UsageHeatMap from "./UsageHeatMap"; +import { useLocation } from "react-router-dom"; const HomeSidebar = () => { + const location = useLocation(); const layoutStore = useLayoutStore(); const showHomeSidebar = layoutStore.state.showHomeSidebar; @@ -20,7 +22,7 @@ const HomeSidebar = () => { }; window.addEventListener("resize", handleWindowResize); handleWindowResize(); - }, []); + }, [location]); return (
{ onClick={() => layoutStore.setHomeSidebarStatus(false)} >