refactor: crée un hook useYear

pull/3233/head
Alice Dahan 2024-11-26 13:23:49 +01:00 committed by liliced
parent 8ed09a958d
commit 50822f1352
2 changed files with 12 additions and 6 deletions

View File

@ -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.

View File

@ -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()
)
}