✨ Add narrator texts infrastructure with API (Story 3.1)
- 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>
This commit is contained in:
53
frontend/app/composables/useFetchNarratorText.ts
Normal file
53
frontend/app/composables/useFetchNarratorText.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
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 }
|
||||
}
|
||||
Reference in New Issue
Block a user