fix(api): type-safe focusFactValue lookup
Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>
This commit is contained in:
parent
3a3e0b3e27
commit
90c24c1a56
@ -50,7 +50,7 @@ export interface FocusOption {
|
||||
apps: string[];
|
||||
}
|
||||
|
||||
const FOCUS_FACTS: Record<string, Record<FocusOption["id"], string>> = {
|
||||
const FOCUS_FACTS = {
|
||||
en: {
|
||||
day: "Wants help with day-to-day work first",
|
||||
inbox: "Wants help with inbox and email first",
|
||||
@ -63,14 +63,17 @@ const FOCUS_FACTS: Record<string, Record<FocusOption["id"], string>> = {
|
||||
research: "Möchte zuerst bei Recherche und Schreiben unterstützt werden",
|
||||
crew: "Möchte eine koordinierte Crew aus Spezialisten-Bots",
|
||||
},
|
||||
};
|
||||
} as const satisfies Record<string, Record<FocusOption["id"], string>>;
|
||||
|
||||
/** Profile fact text for a focus answer, in the user's locale (defaults to English). */
|
||||
function isFocusOptionId(id: string): id is FocusOption["id"] {
|
||||
return FOCUS_OPTIONS.some((option) => option.id === id);
|
||||
}
|
||||
|
||||
export function focusFactValue(focusId: string, locale: string): string {
|
||||
const id = focusId as FocusOption["id"];
|
||||
if (!isFocusOptionId(focusId)) return focusId;
|
||||
const key = locale.toLowerCase().startsWith("de") ? "de" : "en";
|
||||
const table = FOCUS_FACTS[key];
|
||||
return table[id] ?? FOCUS_FACTS.en[id] ?? focusId;
|
||||
return FOCUS_FACTS[key][focusId] ?? FOCUS_FACTS.en[focusId];
|
||||
}
|
||||
|
||||
export const FOCUS_OPTIONS: FocusOption[] = [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user