fix(lint): 4 erreurs ESLint corrigées — split SimulationFlowProvider, hook conditionnel, ref render, setState effect

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hermann_Kitio 2026-04-23 03:05:14 +03:00
parent de69b3ff16
commit 79bbbdc4e8
10 changed files with 82 additions and 50 deletions

View file

@ -8,7 +8,7 @@
* Règle H : aucune logique métier les mutations s'appuient sur entities/.
*/
import { createContext, useContext, useEffect, useRef, useState, type ReactNode } from 'react'
import { useEffect, useRef, useState, type ReactNode } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import { useMutation } from '@tanstack/react-query'
import {
@ -17,43 +17,15 @@ import {
updateSujet as updateSujetApi,
} from '@/entities/production/api'
import { correctEe } from '@/entities/report/api'
import type {
CreateSimulationPayload,
Production,
SujetData,
Tache,
} from '@/entities/production/types'
import type { CreateSimulationPayload, Production, Tache } from '@/entities/production/types'
import type { Report } from '@/entities/report/types'
import type { ApiError } from '@/shared/types/api'
export type SimulationStep =
| 'idle'
| 'choosing-subject'
| 'task-selected'
| 'correcting'
| 'done'
import type { SujetData } from '@/entities/production/types'
import { SimulationFlowContext, type FlowValue, type SimulationStep } from './simulationFlow'
const TACHES_SANS_CATALOGUE: Tache[] = ['EO_T1']
const LS_SIMULATION_ID_KEY = 'expria_simulation_id'
interface FlowValue {
step: SimulationStep
production: Production | null
sujet: SujetData | null
report: Report | null
isCreating: boolean
isCorrecting: boolean
createError: ApiError | null
correctError: ApiError | null
selectTask: (payload: CreateSimulationPayload) => void
submitText: (texte: string, nclcCible?: 9 | 10) => void
changeSubject: (sujet: SujetData) => void
setStep: (step: SimulationStep) => void
reset: () => void
}
const SimulationFlowContext = createContext<FlowValue | null>(null)
export function SimulationFlowProvider({ children }: { children: ReactNode }) {
const [step, setStep] = useState<SimulationStep>('idle')
const [production, setProduction] = useState<Production | null>(null)
@ -178,11 +150,3 @@ export function SimulationFlowProvider({ children }: { children: ReactNode }) {
<SimulationFlowContext.Provider value={value}>{children}</SimulationFlowContext.Provider>
)
}
export function useSimulationFlow(): FlowValue {
const ctx = useContext(SimulationFlowContext)
if (!ctx) {
throw new Error('useSimulationFlow doit être utilisé dans un <SimulationFlowProvider>.')
}
return ctx
}

View file

@ -0,0 +1,49 @@
/**
* Types, contexte et hook du flux simulation.
*
* Extrait de SimulationFlowProvider.tsx pour respecter la règle
* `react-refresh/only-export-components` : un fichier de composant ne peut
* pas -exporter types / hooks / contextes.
*/
import { createContext, useContext } from 'react'
import type {
CreateSimulationPayload,
Production,
SujetData,
} from '@/entities/production/types'
import type { Report } from '@/entities/report/types'
import type { ApiError } from '@/shared/types/api'
export type SimulationStep =
| 'idle'
| 'choosing-subject'
| 'task-selected'
| 'correcting'
| 'done'
export interface FlowValue {
step: SimulationStep
production: Production | null
sujet: SujetData | null
report: Report | null
isCreating: boolean
isCorrecting: boolean
createError: ApiError | null
correctError: ApiError | null
selectTask: (payload: CreateSimulationPayload) => void
submitText: (texte: string, nclcCible?: 9 | 10) => void
changeSubject: (sujet: SujetData) => void
setStep: (step: SimulationStep) => void
reset: () => void
}
export const SimulationFlowContext = createContext<FlowValue | null>(null)
export function useSimulationFlow(): FlowValue {
const ctx = useContext(SimulationFlowContext)
if (!ctx) {
throw new Error('useSimulationFlow doit être utilisé dans un <SimulationFlowProvider>.')
}
return ctx
}