- Create narrator_texts table migration with context/hero_type indexes
- Add NarratorText model with getRandomText() for variant selection
- Add NarratorTextSeeder with 30+ texts for 11 contexts
- Implement vouvoiement (recruteur) vs tutoiement (client/dev)
- Create NarratorController with GET /api/narrator/{context}
- Add useFetchNarratorText composable for frontend
Contexts: intro, transitions, hints, encouragements, contact_unlocked, welcome_back
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
export type NarratorContext =
|
|
| 'intro'
|
|
| 'transition_projects'
|
|
| 'transition_skills'
|
|
| 'transition_testimonials'
|
|
| 'transition_journey'
|
|
| 'hint'
|
|
| 'encouragement_25'
|
|
| 'encouragement_50'
|
|
| 'encouragement_75'
|
|
| 'contact_unlocked'
|
|
| 'welcome_back'
|
|
|
|
export type HeroType = 'recruteur' | 'client' | 'dev'
|
|
|
|
export interface NarratorTextData {
|
|
context: string
|
|
text: string
|
|
variant: number
|
|
hero_type: HeroType | null
|
|
}
|
|
|
|
interface NarratorTextResponse {
|
|
data: NarratorTextData
|
|
meta: { lang: string }
|
|
}
|
|
|
|
export function useFetchNarratorText() {
|
|
const config = useRuntimeConfig()
|
|
const { locale } = useI18n()
|
|
|
|
async function fetchText(context: NarratorContext, heroType?: HeroType): Promise<NarratorTextData | null> {
|
|
try {
|
|
const url = heroType
|
|
? `/narrator/${context}?hero=${heroType}`
|
|
: `/narrator/${context}`
|
|
|
|
const response = await $fetch<NarratorTextResponse>(url, {
|
|
baseURL: config.public.apiUrl as string,
|
|
headers: {
|
|
'X-API-Key': config.public.apiKey as string,
|
|
'Accept-Language': locale.value,
|
|
},
|
|
})
|
|
|
|
return response.data
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
return { fetchText }
|
|
}
|