From bce457e0f30e9b2b72ecd5d3d80d9d33bb01f2da Mon Sep 17 00:00:00 2001 From: Santiago Date: Sat, 13 Apr 2024 14:58:05 -0300 Subject: [PATCH] change redux legacy updates method --- app/react/App.tsx | 28 ++++++++++++++++++------- app/react/V2/atoms/relationshipTypes.ts | 8 ------- app/react/V2/atoms/settingsAtom.ts | 8 ------- app/react/V2/atoms/templatesAtom.tsx | 8 ------- app/react/entry-server.tsx | 9 +++----- package.json | 1 - yarn.lock | 5 ----- 7 files changed, 23 insertions(+), 44 deletions(-) diff --git a/app/react/App.tsx b/app/react/App.tsx index 104f84d800..62816afd06 100644 --- a/app/react/App.tsx +++ b/app/react/App.tsx @@ -5,6 +5,7 @@ import { Provider as ReduxProvider } from 'react-redux'; import { getRoutes } from './Routes'; import CustomProvider from './App/Provider'; import { settingsAtom, templatesAtom, translationsAtom } from './V2/atoms'; +import { relationshipTypesAtom } from './V2/atoms/relationshipTypes'; import { store } from './store'; const reduxState = store?.getState(); @@ -14,18 +15,29 @@ const templates = reduxState?.templates.toJS() || []; const router = createBrowserRouter(getRoutes(settings, reduxState?.user.get('_id'))); -const atomsGlobalState = () => { - const myStore = createStore(); - myStore.set(settingsAtom, settings); - myStore.set(templatesAtom, templates); - myStore.set(translationsAtom, { locale: reduxState?.locale || 'en' }); - return myStore; -}; +const atomStore = createStore(); +atomStore.set(settingsAtom, settings); +atomStore.set(templatesAtom, templates); +atomStore.set(translationsAtom, { locale: reduxState?.locale || 'en' }); + +//sync deprecated redux store +atomStore.sub(settingsAtom, () => { + const value = atomStore.get(settingsAtom); + store?.dispatch({ type: 'settings/collection/SET', value }); +}); +atomStore.sub(templatesAtom, () => { + const value = atomStore.get(templatesAtom); + store?.dispatch({ type: 'templates/SET', value }); +}); +atomStore.sub(relationshipTypesAtom, () => { + const value = atomStore.get(relationshipTypesAtom); + store?.dispatch({ type: 'relationTypes/SET', value }); +}); const App = () => ( - + diff --git a/app/react/V2/atoms/relationshipTypes.ts b/app/react/V2/atoms/relationshipTypes.ts index 42f88deebf..a69e091fd5 100644 --- a/app/react/V2/atoms/relationshipTypes.ts +++ b/app/react/V2/atoms/relationshipTypes.ts @@ -1,14 +1,6 @@ import { atom } from 'jotai'; -import { atomEffect } from 'jotai-effect'; import { ClientRelationshipType } from 'app/apiResponseTypes'; -import { store } from 'app/store'; const relationshipTypesAtom = atom([] as ClientRelationshipType[]); -//sync deprecated redux store -atomEffect(get => { - const value = get(relationshipTypesAtom); - store?.dispatch({ type: 'relationTypes/SET', value }); -}); - export { relationshipTypesAtom }; diff --git a/app/react/V2/atoms/settingsAtom.ts b/app/react/V2/atoms/settingsAtom.ts index 55f87894dd..a56cf2c5fc 100644 --- a/app/react/V2/atoms/settingsAtom.ts +++ b/app/react/V2/atoms/settingsAtom.ts @@ -1,14 +1,6 @@ import { atom } from 'jotai'; -import { atomEffect } from 'jotai-effect'; -import { store } from 'app/store'; import { ClientSettings } from 'app/apiResponseTypes'; const settingsAtom = atom({} as ClientSettings); -//sync deprecated redux store -atomEffect(get => { - const value = get(settingsAtom); - store?.dispatch({ type: 'settings/collection/SET', value }); -}); - export { settingsAtom }; diff --git a/app/react/V2/atoms/templatesAtom.tsx b/app/react/V2/atoms/templatesAtom.tsx index 778347bb42..381b97efcf 100644 --- a/app/react/V2/atoms/templatesAtom.tsx +++ b/app/react/V2/atoms/templatesAtom.tsx @@ -1,14 +1,6 @@ import { atom } from 'jotai'; -import { atomEffect } from 'jotai-effect'; -import { store } from 'app/store'; import { Template } from 'app/apiResponseTypes'; const templatesAtom = atom([] as Template[]); -//sync deprecated redux store -atomEffect(get => { - const value = get(templatesAtom); - store?.dispatch({ type: 'templates/SET', value }); -}); - export { templatesAtom }; diff --git a/app/react/entry-server.tsx b/app/react/entry-server.tsx index 80eb181e90..412e0a0acd 100644 --- a/app/react/entry-server.tsx +++ b/app/react/entry-server.tsx @@ -272,16 +272,13 @@ const EntryServer = async (req: ExpressRequest, res: Response) => { resetTranslations(); - const atomsGlobalState = () => { - const myStore = createStore(); - myStore.set(settingsAtom, settings); - return myStore; - }; + const atomStore = createStore(); + atomStore.set(settingsAtom, settings); const componentHtml = ReactDOMServer.renderToString( - +