feat(simulations): getIdees API + hook useIdees (G5)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
555dac17e2
commit
67eb3411c5
2 changed files with 48 additions and 0 deletions
|
|
@ -42,3 +42,18 @@ export function correctEo(payload: CorrectEoPayload): Promise<Report> {
|
||||||
timeoutMs: CORRECTION_TIMEOUT_MS,
|
timeoutMs: CORRECTION_TIMEOUT_MS,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const IDEES_TIMEOUT_MS = 15_000
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère 5 suggestions d'idées DeepSeek pour prolonger la rédaction en cours.
|
||||||
|
* Endpoint : `POST /sujets/idees`. Tâche G5.
|
||||||
|
* Contraintes backend : sujet_consigne non vide + contenu_partiel ≥ 30 mots.
|
||||||
|
*/
|
||||||
|
export function getIdees(consigne: string, contenu: string): Promise<string[]> {
|
||||||
|
return apiFetch<{ idees: string[] }>('/sujets/idees', {
|
||||||
|
method: 'POST',
|
||||||
|
body: { sujet_consigne: consigne, contenu_partiel: contenu },
|
||||||
|
timeoutMs: IDEES_TIMEOUT_MS,
|
||||||
|
}).then((res) => res.idees)
|
||||||
|
}
|
||||||
|
|
|
||||||
33
src/features/simulations/hooks/useIdees.ts
Normal file
33
src/features/simulations/hooks/useIdees.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/**
|
||||||
|
* Hook — suggestions d'idées DeepSeek pour prolonger une rédaction en cours.
|
||||||
|
*
|
||||||
|
* Tâche G5 : mutation sur POST /sujets/idees. Retourne les idées, l'état
|
||||||
|
* de chargement, l'erreur API et un `reset()` pour vider le cache de la
|
||||||
|
* mutation (appelé à la fermeture du modal côté composant).
|
||||||
|
*
|
||||||
|
* Règle H : aucune logique métier — la garde `hasAccess(plan, 'tips')`
|
||||||
|
* est appliquée dans SimulationForm (UX), jamais ici.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { useMutation } from '@tanstack/react-query'
|
||||||
|
import { getIdees } from '@/entities/report/api'
|
||||||
|
import type { ApiError } from '@/shared/types/api'
|
||||||
|
|
||||||
|
interface FetchIdeesVariables {
|
||||||
|
consigne: string
|
||||||
|
contenu: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useIdees() {
|
||||||
|
const mutation = useMutation<string[], ApiError, FetchIdeesVariables>({
|
||||||
|
mutationFn: ({ consigne, contenu }) => getIdees(consigne, contenu),
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
idees: mutation.data ?? null,
|
||||||
|
isLoading: mutation.isPending,
|
||||||
|
error: mutation.error as ApiError | null,
|
||||||
|
fetchIdees: (variables: FetchIdeesVariables) => mutation.mutate(variables),
|
||||||
|
reset: mutation.reset,
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue