From 50822f1352849e1ed072897b38f6ab7e9e90b29e Mon Sep 17 00:00:00 2001 From: Alice Dahan Date: Tue, 26 Nov 2024 13:23:49 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20cr=C3=A9e=20un=20hook=20useYear?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site/source/components/SelectSimulationYear.tsx | 9 +++------ site/source/components/utils/useYear.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 site/source/components/utils/useYear.ts diff --git a/site/source/components/SelectSimulationYear.tsx b/site/source/components/SelectSimulationYear.tsx index 56a2f6518..af0bab7a5 100644 --- a/site/source/components/SelectSimulationYear.tsx +++ b/site/source/components/SelectSimulationYear.tsx @@ -1,25 +1,22 @@ -import { useContext } from 'react' import { Trans } from 'react-i18next' import { useDispatch } from 'react-redux' import { styled } from 'styled-components' import Banner from '@/components/Banner' -import { EngineContext } from '@/components/utils/EngineContext' import { Link as DesignSystemLink } from '@/design-system/typography/link' import { enregistreLaRéponse } from '@/store/actions/actions' +import useYear from './utils/useYear' + const Bold = styled.span<{ $bold: boolean }>` ${({ $bold }) => ($bold ? 'font-weight: bold;' : '')} ` export const SelectSimulationYear = () => { const dispatch = useDispatch() - const year = useContext(EngineContext).evaluate('date') const choices = [2023, 2024] - const actualYear = Number( - year.nodeValue?.toString().slice(-4) || new Date().getFullYear() - ) + const actualYear = useYear() // return null // Waiting for next year. diff --git a/site/source/components/utils/useYear.ts b/site/source/components/utils/useYear.ts new file mode 100644 index 000000000..2cf805c4b --- /dev/null +++ b/site/source/components/utils/useYear.ts @@ -0,0 +1,9 @@ +import { useEngine } from './EngineContext' + +export default function useYear() { + const year = useEngine().evaluate('date') + + return Number( + year.nodeValue?.toString().slice(-4) || new Date().getFullYear() + ) +}