From 26bd0ce16b60b3590a49381ee13cb2f9699315e5 Mon Sep 17 00:00:00 2001 From: Ivan <8611739+IRBorisov@users.noreply.github.com> Date: Tue, 14 Jan 2025 21:57:32 +0300 Subject: [PATCH] R: Migrating to zustand for local state management pt1 --- README.md | 1 + rsconcept/frontend/package-lock.json | 190 +++++++++++++++++- rsconcept/frontend/package.json | 3 +- .../frontend/src/app/ApplicationLayout.tsx | 11 +- rsconcept/frontend/src/app/Footer.tsx | 5 - .../src/app/Navigation/Navigation.tsx | 4 +- .../src/app/Navigation/ToggleNavigation.tsx | 6 +- .../src/app/Navigation/UserDropdown.tsx | 8 +- .../frontend/src/app/Navigation/UserMenu.tsx | 4 +- .../src/components/info/BadgeHelp.tsx | 4 +- .../src/components/ui/PDFViewer/PDFViewer.tsx | 5 +- .../src/context/ConceptOptionsContext.tsx | 81 +------- .../frontend/src/context/LibraryContext.tsx | 4 +- .../frontend/src/pages/DatabaseSchemaPage.tsx | 12 +- .../src/pages/LibraryPage/LibraryPage.tsx | 4 +- .../pages/LibraryPage/TableLibraryItems.tsx | 5 +- .../pages/LibraryPage/ViewSideLocation.tsx | 5 +- .../src/pages/ManualsPage/ManualsPage.tsx | 4 +- .../src/pages/ManualsPage/TopicsDropdown.tsx | 7 +- .../src/pages/ManualsPage/TopicsStatic.tsx | 6 +- .../src/pages/ManualsPage/ViewTopic.tsx | 4 +- .../pages/OssPage/EditorOssGraph/OssFlow.tsx | 4 +- .../src/pages/OssPage/OssEditContext.tsx | 4 +- .../frontend/src/pages/OssPage/OssTabs.tsx | 8 +- .../EditorConstituenta/EditorConstituenta.tsx | 4 +- .../RSFormPage/EditorRSList/EditorRSList.tsx | 5 +- .../RSFormPage/EditorTermGraph/TGFlow.tsx | 4 +- .../RSFormPage/EditorTermGraph/ViewHidden.tsx | 5 +- .../src/pages/RSFormPage/RSEditContext.tsx | 4 +- .../frontend/src/pages/RSFormPage/RSTabs.tsx | 10 +- .../ViewConstituents/ViewConstituents.tsx | 10 +- rsconcept/frontend/src/stores/appLayout.ts | 68 +++++++ rsconcept/frontend/src/stores/preferences.ts | 24 +++ rsconcept/frontend/src/utils/constants.ts | 2 - 34 files changed, 357 insertions(+), 168 deletions(-) create mode 100644 rsconcept/frontend/src/stores/appLayout.ts create mode 100644 rsconcept/frontend/src/stores/preferences.ts diff --git a/README.md b/README.md index 308593cd..7dd55b54 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ This readme file is used mostly to document project dependencies and conventions - use-debounce - qrcode.react - html-to-image + - zustand - @tanstack/react-table - @uiw/react-codemirror - @uiw/codemirror-themes diff --git a/rsconcept/frontend/package-lock.json b/rsconcept/frontend/package-lock.json index b0d339c9..26de177c 100644 --- a/rsconcept/frontend/package-lock.json +++ b/rsconcept/frontend/package-lock.json @@ -30,7 +30,8 @@ "react-tooltip": "^5.28.0", "react-zoom-pan-pinch": "^3.6.1", "reactflow": "^11.11.4", - "use-debounce": "^10.0.4" + "use-debounce": "^10.0.4", + "zustand": "^5.0.3" }, "devDependencies": { "@lezer/generator": "^1.7.2", @@ -2445,6 +2446,34 @@ "react-dom": ">=17" } }, + "node_modules/@reactflow/background/node_modules/zustand": { + "version": "4.5.6", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.6.tgz", + "integrity": "sha512-ibr/n1hBzLLj5Y+yUcU7dYw8p6WnIVzdJbnX+1YpaScvZVF2ziugqHs+LAmHw4lWO9c/zRj+K1ncgWDQuthEdQ==", + "license": "MIT", + "dependencies": { + "use-sync-external-store": "^1.2.2" + }, + "engines": { + "node": ">=12.7.0" + }, + "peerDependencies": { + "@types/react": ">=16.8", + "immer": ">=9.0.6", + "react": ">=16.8" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + } + } + }, "node_modules/@reactflow/controls": { "version": "11.2.14", "resolved": "https://registry.npmjs.org/@reactflow/controls/-/controls-11.2.14.tgz", @@ -2460,6 +2489,34 @@ "react-dom": ">=17" } }, + "node_modules/@reactflow/controls/node_modules/zustand": { + "version": "4.5.6", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.6.tgz", + "integrity": "sha512-ibr/n1hBzLLj5Y+yUcU7dYw8p6WnIVzdJbnX+1YpaScvZVF2ziugqHs+LAmHw4lWO9c/zRj+K1ncgWDQuthEdQ==", + "license": "MIT", + "dependencies": { + "use-sync-external-store": "^1.2.2" + }, + "engines": { + "node": ">=12.7.0" + }, + "peerDependencies": { + "@types/react": ">=16.8", + "immer": ">=9.0.6", + "react": ">=16.8" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + } + } + }, "node_modules/@reactflow/core": { "version": "11.11.4", "resolved": "https://registry.npmjs.org/@reactflow/core/-/core-11.11.4.tgz", @@ -2481,6 +2538,34 @@ "react-dom": ">=17" } }, + "node_modules/@reactflow/core/node_modules/zustand": { + "version": "4.5.6", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.6.tgz", + "integrity": "sha512-ibr/n1hBzLLj5Y+yUcU7dYw8p6WnIVzdJbnX+1YpaScvZVF2ziugqHs+LAmHw4lWO9c/zRj+K1ncgWDQuthEdQ==", + "license": "MIT", + "dependencies": { + "use-sync-external-store": "^1.2.2" + }, + "engines": { + "node": ">=12.7.0" + }, + "peerDependencies": { + "@types/react": ">=16.8", + "immer": ">=9.0.6", + "react": ">=16.8" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + } + } + }, "node_modules/@reactflow/minimap": { "version": "11.7.14", "resolved": "https://registry.npmjs.org/@reactflow/minimap/-/minimap-11.7.14.tgz", @@ -2500,6 +2585,34 @@ "react-dom": ">=17" } }, + "node_modules/@reactflow/minimap/node_modules/zustand": { + "version": "4.5.6", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.6.tgz", + "integrity": "sha512-ibr/n1hBzLLj5Y+yUcU7dYw8p6WnIVzdJbnX+1YpaScvZVF2ziugqHs+LAmHw4lWO9c/zRj+K1ncgWDQuthEdQ==", + "license": "MIT", + "dependencies": { + "use-sync-external-store": "^1.2.2" + }, + "engines": { + "node": ">=12.7.0" + }, + "peerDependencies": { + "@types/react": ">=16.8", + "immer": ">=9.0.6", + "react": ">=16.8" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + } + } + }, "node_modules/@reactflow/node-resizer": { "version": "2.2.14", "resolved": "https://registry.npmjs.org/@reactflow/node-resizer/-/node-resizer-2.2.14.tgz", @@ -2517,6 +2630,34 @@ "react-dom": ">=17" } }, + "node_modules/@reactflow/node-resizer/node_modules/zustand": { + "version": "4.5.6", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.6.tgz", + "integrity": "sha512-ibr/n1hBzLLj5Y+yUcU7dYw8p6WnIVzdJbnX+1YpaScvZVF2ziugqHs+LAmHw4lWO9c/zRj+K1ncgWDQuthEdQ==", + "license": "MIT", + "dependencies": { + "use-sync-external-store": "^1.2.2" + }, + "engines": { + "node": ">=12.7.0" + }, + "peerDependencies": { + "@types/react": ">=16.8", + "immer": ">=9.0.6", + "react": ">=16.8" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + } + } + }, "node_modules/@reactflow/node-toolbar": { "version": "1.3.14", "resolved": "https://registry.npmjs.org/@reactflow/node-toolbar/-/node-toolbar-1.3.14.tgz", @@ -2532,6 +2673,34 @@ "react-dom": ">=17" } }, + "node_modules/@reactflow/node-toolbar/node_modules/zustand": { + "version": "4.5.6", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.6.tgz", + "integrity": "sha512-ibr/n1hBzLLj5Y+yUcU7dYw8p6WnIVzdJbnX+1YpaScvZVF2ziugqHs+LAmHw4lWO9c/zRj+K1ncgWDQuthEdQ==", + "license": "MIT", + "dependencies": { + "use-sync-external-store": "^1.2.2" + }, + "engines": { + "node": ">=12.7.0" + }, + "peerDependencies": { + "@types/react": ">=16.8", + "immer": ">=9.0.6", + "react": ">=16.8" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + } + } + }, "node_modules/@rollup/rollup-android-arm-eabi": { "version": "4.30.1", "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.30.1.tgz", @@ -10711,20 +10880,18 @@ } }, "node_modules/zustand": { - "version": "4.5.6", - "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.6.tgz", - "integrity": "sha512-ibr/n1hBzLLj5Y+yUcU7dYw8p6WnIVzdJbnX+1YpaScvZVF2ziugqHs+LAmHw4lWO9c/zRj+K1ncgWDQuthEdQ==", + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-5.0.3.tgz", + "integrity": "sha512-14fwWQtU3pH4dE0dOpdMiWjddcH+QzKIgk1cl8epwSE7yag43k/AD/m4L6+K7DytAOr9gGBe3/EXj9g7cdostg==", "license": "MIT", - "dependencies": { - "use-sync-external-store": "^1.2.2" - }, "engines": { - "node": ">=12.7.0" + "node": ">=12.20.0" }, "peerDependencies": { - "@types/react": ">=16.8", + "@types/react": ">=18.0.0", "immer": ">=9.0.6", - "react": ">=16.8" + "react": ">=18.0.0", + "use-sync-external-store": ">=1.2.0" }, "peerDependenciesMeta": { "@types/react": { @@ -10735,6 +10902,9 @@ }, "react": { "optional": true + }, + "use-sync-external-store": { + "optional": true } } } diff --git a/rsconcept/frontend/package.json b/rsconcept/frontend/package.json index ca9d8d3f..9eb04b28 100644 --- a/rsconcept/frontend/package.json +++ b/rsconcept/frontend/package.json @@ -34,7 +34,8 @@ "react-tooltip": "^5.28.0", "react-zoom-pan-pinch": "^3.6.1", "reactflow": "^11.11.4", - "use-debounce": "^10.0.4" + "use-debounce": "^10.0.4", + "zustand": "^5.0.3" }, "devDependencies": { "@lezer/generator": "^1.7.2", diff --git a/rsconcept/frontend/src/app/ApplicationLayout.tsx b/rsconcept/frontend/src/app/ApplicationLayout.tsx index 5a949647..e9fe77ac 100644 --- a/rsconcept/frontend/src/app/ApplicationLayout.tsx +++ b/rsconcept/frontend/src/app/ApplicationLayout.tsx @@ -5,12 +5,17 @@ import ConceptToaster from '@/app/ConceptToaster'; import Footer from '@/app/Footer'; import Navigation from '@/app/Navigation'; import Loader from '@/components/ui/Loader'; -import { useConceptOptions } from '@/context/ConceptOptionsContext'; import { NavigationState } from '@/context/NavigationContext'; +import { useAppLayoutStore, useMainHeight, useViewportHeight } from '@/stores/appLayout'; import { globals } from '@/utils/constants'; function ApplicationLayout() { - const { viewportHeight, mainHeight, showScroll, noNavigationAnimation } = useConceptOptions(); + const mainHeight = useMainHeight(); + const viewportHeight = useViewportHeight(); + const showScroll = useAppLayoutStore(state => !state.noScroll); + const noNavigationAnimation = useAppLayoutStore(state => state.noNavigationAnimation); + const noNavigation = useAppLayoutStore(state => state.noNavigation); + const noFooter = useAppLayoutStore(state => state.noFooter); return (
@@ -36,7 +41,7 @@ function ApplicationLayout() { -
diff --git a/rsconcept/frontend/src/app/Footer.tsx b/rsconcept/frontend/src/app/Footer.tsx index b39aa0f7..fc1b4b76 100644 --- a/rsconcept/frontend/src/app/Footer.tsx +++ b/rsconcept/frontend/src/app/Footer.tsx @@ -1,15 +1,10 @@ import clsx from 'clsx'; -import { useConceptOptions } from '@/context/ConceptOptionsContext'; import { external_urls } from '@/utils/constants'; import TextURL from '../components/ui/TextURL'; function Footer() { - const { noNavigation, noFooter } = useConceptOptions(); - if (noNavigation || noFooter) { - return null; - } return (