-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compliqué la gestion des searchparams
- Loading branch information
Showing
15 changed files
with
321 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NEXT_PUBLIC_NODE_ENV=development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
'use client' | ||
|
||
import reducers from '@/app/reducers' | ||
import { PropsWithChildren } from 'react' | ||
import { PropsWithChildren, useMemo } from 'react' | ||
import { Provider } from 'react-redux' | ||
import { createStore } from 'redux' | ||
import { applyMiddleware, createStore, compose } from 'redux' | ||
import thunk from 'redux-thunk' | ||
|
||
const composeEnhancers = | ||
(typeof window !== 'undefined' && | ||
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) || | ||
compose | ||
|
||
export default function ReduxProvider({ children }: PropsWithChildren) { | ||
const store = createStore(reducers) | ||
const store = useMemo(() => { | ||
const storeEnhancer = applyMiddleware(thunk) | ||
return createStore(reducers, {}, composeEnhancers(storeEnhancer)) | ||
}, []) | ||
|
||
return <Provider store={store}>{children}</Provider> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client' | ||
|
||
import { setSimulationConfig } from '@/app/actions' | ||
import { questionEcoDimensions } from '@/app/components/questionEcoDimensions' | ||
import { parentName } from 'Components/utils/publicodesUtils' | ||
import { usePathname } from 'next/navigation' | ||
import { compose, isEmpty, symmetricDifference } from 'ramda' | ||
import { useEffect } from 'react' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import configBuilder from './configBuilder' | ||
import SimulateurContent from './SimulateurContent' | ||
|
||
const eqValues = compose(isEmpty, symmetricDifference) | ||
|
||
export default ({ dottedName }) => { | ||
const dispatch = useDispatch() | ||
const pathname = usePathname() | ||
|
||
const rules = useSelector((state) => state.rules) | ||
|
||
if (!rules) return 'Les règles ne sont pas chargées' | ||
const decodedRule = rules[dottedName] | ||
|
||
if (!decodedRule) return 'Règle non trouvée' | ||
const objectifs = | ||
decodedRule.exposé?.type === 'question éco' | ||
? questionEcoDimensions.map( | ||
(dimension) => parentName(dottedName) + ' . ' + dimension | ||
) | ||
: [dottedName] | ||
|
||
const config = configBuilder(objectifs, dottedName), | ||
configSet = useSelector((state) => state.simulation?.config) | ||
const wrongConfig = !eqValues(config.objectifs, configSet?.objectifs || []) | ||
useEffect( | ||
() => | ||
wrongConfig | ||
? dispatch(setSimulationConfig(config, pathname)) | ||
: () => null, | ||
[] | ||
) | ||
|
||
if (!configSet || wrongConfig) return null | ||
|
||
return <SimulateurContent objective={dottedName} /> | ||
} |
Oops, something went wrong.