- api/names.ts: suggestNames() + buildSuggestPath() + NAMEGEN_USAGES (norn/japa/mythg/ger/arb) - de.ts: namegen-Sektion (button, panelTitle, letter/usages/load/states) - NameSuggestPanel.tsx: inline-Panel mit Buchstabe/Herkunftskultur-Multiselect, Vorschlagsliste; 503 NamesKeyMissing → freundlicher Hinweis - GerbilFormPage: 'Name vorschlagen'-Button neben Namensfeld (htmlFor-Pattern), Panel schließt+befüllt bei Auswahl - vitest: 11 Tests (buildSuggestPath URL-Logik + NAMEGEN_USAGES-Struktur) - e2e: mock /names/suggest + namesConfigured-Flag; 4 Specs (Panel öffnen, Klick befüllt, Buchstabe-Filter, 503-Fallback) Gate: vitest 104/104, e2e 156/156, tsc clean
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
/** FEAT-NAMEGEN: Namensvorschläge — Schnittstelle zum Backend /names/suggest. */
|
|
import { api } from './client'
|
|
|
|
export interface NameSuggestion {
|
|
name: string
|
|
meaning: string
|
|
origin: string
|
|
}
|
|
|
|
export const NAMEGEN_USAGES = [
|
|
{ code: 'norn', label: 'Nordisch' },
|
|
{ code: 'japa', label: 'Japanisch' },
|
|
{ code: 'mythg', label: 'Griech. Mythologie' },
|
|
{ code: 'ger', label: 'Deutsch' },
|
|
{ code: 'arb', label: 'Arabisch' },
|
|
] as const
|
|
|
|
export type NamegenUsageCode = (typeof NAMEGEN_USAGES)[number]['code']
|
|
|
|
export interface SuggestNamesParams {
|
|
letter?: string
|
|
gender?: string
|
|
usages: NamegenUsageCode[]
|
|
count?: number
|
|
}
|
|
|
|
/** Exported for unit tests — builds the query path without a network call. */
|
|
export function buildSuggestPath(params: SuggestNamesParams): string {
|
|
const parts: string[] = []
|
|
const letter = params.letter?.trim().toUpperCase()
|
|
if (letter) parts.push(`letter=${encodeURIComponent(letter)}`)
|
|
if (params.gender && params.gender !== '') parts.push(`gender=${encodeURIComponent(params.gender)}`)
|
|
if (params.usages.length > 0) parts.push(`usages=${params.usages.join(',')}`)
|
|
parts.push(`count=${params.count ?? 6}`)
|
|
return `/names/suggest?${parts.join('&')}`
|
|
}
|
|
|
|
export function suggestNames(params: SuggestNamesParams): Promise<NameSuggestion[]> {
|
|
return api.get<NameSuggestion[]>(buildSuggestPath(params))
|
|
}
|