generated from graasp/graasp-app-starter-ts-vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: update the simulation info size to stop blicking * feat: use loop instead of reduce * feat(refactor): remove HouseComponentsConfigurator * feat(refactor): put the logic in useHouseComponents * feat: improve the performances of SimulationHeatLoss by using for loop * feat: unmount chart to improve performances * feat(test): write new tests for useHouseComponents * fix(test): add some timeout for flacky tests
- Loading branch information
Showing
28 changed files
with
1,466 additions
and
921 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
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,65 @@ | ||
import { ReactNode, createContext, useContext, useMemo, useState } from 'react'; | ||
|
||
import { undefinedContextErrorFactory } from '@/utils/context'; | ||
|
||
type Period = { | ||
numberOfDays: number; | ||
labelKey: | ||
| 'ONE_MONTH' | ||
| 'THREE_MONTHS' | ||
| 'SIX_MONTHS' | ||
| 'ONE_YEAR' | ||
| 'THREE_YEARS'; | ||
}; | ||
|
||
export const PERIODS: Period[] = [ | ||
{ numberOfDays: 30, labelKey: 'ONE_MONTH' }, | ||
{ numberOfDays: 90, labelKey: 'THREE_MONTHS' }, | ||
{ numberOfDays: 180, labelKey: 'SIX_MONTHS' }, | ||
{ numberOfDays: 365, labelKey: 'ONE_YEAR' }, | ||
{ numberOfDays: 1_095, labelKey: 'THREE_YEARS' }, | ||
] as const; | ||
|
||
type ChartContextType = { | ||
period: Period; | ||
updatePeriod: (periodValue: number) => void; | ||
}; | ||
|
||
const ChartContext = createContext<ChartContextType | null>(null); | ||
|
||
type Props = { | ||
children: ReactNode; | ||
}; | ||
|
||
export const ChartProvider = ({ children }: Props): ReactNode => { | ||
const [period, setPeriod] = useState(PERIODS[0]); | ||
|
||
const updatePeriod = (periodValue: number): void => | ||
setPeriod( | ||
PERIODS.find((p) => periodValue === p.numberOfDays) ?? PERIODS[0], | ||
); | ||
|
||
const contextValue = useMemo( | ||
() => ({ | ||
period, | ||
updatePeriod, | ||
}), | ||
[period], | ||
); | ||
|
||
return ( | ||
<ChartContext.Provider value={contextValue}> | ||
{children} | ||
</ChartContext.Provider> | ||
); | ||
}; | ||
|
||
export const useChart = (): ChartContextType => { | ||
const context = useContext(ChartContext); | ||
|
||
if (!context) { | ||
throw undefinedContextErrorFactory('Chart'); | ||
} | ||
|
||
return context; | ||
}; |
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
Oops, something went wrong.