diff --git a/src/app/features/settings/experimental/Experimental.tsx b/src/app/features/settings/experimental/Experimental.tsx index 8148c92ed..f7962cc4d 100644 --- a/src/app/features/settings/experimental/Experimental.tsx +++ b/src/app/features/settings/experimental/Experimental.tsx @@ -1,7 +1,7 @@ import { Box, Text, IconButton, Icon, Icons, Scroll } from 'folds'; import { Page, PageContent, PageHeader } from '$components/page'; import { InfoCard } from '$components/info-card'; -import { Sync } from '../general'; +import { Sync, LanguageSpecificPronouns } from '../general'; type ExperimentalProps = { requestClose: () => void; @@ -42,6 +42,9 @@ export function Experimental({ requestClose }: ExperimentalProps) { + + + diff --git a/src/app/features/settings/general/LanguageSpecificPronouns.tsx b/src/app/features/settings/general/LanguageSpecificPronouns.tsx new file mode 100644 index 000000000..0458136c6 --- /dev/null +++ b/src/app/features/settings/general/LanguageSpecificPronouns.tsx @@ -0,0 +1,120 @@ +import { Box, Input, Switch, Text } from 'folds'; +import { SettingTile } from '$components/setting-tile'; +import { SequenceCard } from '$components/sequence-card'; +import { useClientConfig } from '$hooks/useClientConfig'; +import { useEffect, useState } from 'react'; +import { SequenceCardStyle } from '../styles.css'; + +// type definition for the language specific pronouns configuration, which can be stored in the client config +export type LanguageSpecificPronounsConfig = { + enabled?: boolean | string; + languages?: string[]; +}; + +export const resolveLanguageSpecificPronounsEnabled = ( + enabled: LanguageSpecificPronounsConfig['enabled'] +): boolean => { + if (enabled === undefined) return false; + if (typeof enabled === 'boolean') return enabled; + const normalized = String(enabled).trim().toLowerCase(); + if (normalized === 'false' || normalized === '0' || normalized === 'off' || normalized === 'no') + return false; + if (normalized === 'true' || normalized === '1' || normalized === 'on' || normalized === 'yes') + return true; + return false; +}; + +// utility function to split a comma separated list of languages and trim whitespace +function splitAndTrimLanguages(languages: string): string[] { + return languages + .split(',') + .map((lang) => lang.trim()) + .filter((lang) => lang.length > 0); +} + +export function LanguageSpecificPronouns() { + const clientConfig = useClientConfig(); + + const [useLanguageSpecificPronouns, setEnabled] = useState(false); + const [languageList, setLanguageList] = useState(''); + + // common handler for saving changes to the language specific pronouns settings + const handleSave = (enabled: boolean, languages: string) => { + clientConfig.languageSpecificPronouns = { + ...clientConfig.languageSpecificPronouns, + enabled, + }; + clientConfig.languageSpecificPronouns = { + ...clientConfig.languageSpecificPronouns, + languages: splitAndTrimLanguages(languages), + }; + }; + + // handler for when the language list input changes + const handleLanguageListChange = (e: React.ChangeEvent) => { + const val = e.target.value.trim(); + setLanguageList(val); + // save the new language list to the client config, keeping the enabled state unchanged + handleSave(clientConfig.languageSpecificPronouns?.enabled ?? false, val); + }; + + useEffect(() => { + setEnabled( + resolveLanguageSpecificPronounsEnabled(clientConfig.languageSpecificPronouns?.enabled) + ); + setLanguageList(clientConfig.languageSpecificPronouns?.languages?.join(',') || ''); + }, [ + clientConfig.languageSpecificPronouns?.enabled, + clientConfig.languageSpecificPronouns?.languages, + ]); + + // handler for toggling the enabled state of language specific pronouns + const handleSetEnabled = (enabled: boolean) => { + console.debug('Updating language specific pronouns enabled to', enabled); + handleSave(enabled, clientConfig.languageSpecificPronouns?.languages?.join(',') || ''); + setEnabled(enabled); + }; + + return ( + + Language Specific Pronouns + + + } + /> + {useLanguageSpecificPronouns && ( + + } + /> + )} + + + ); +} diff --git a/src/app/features/settings/general/index.ts b/src/app/features/settings/general/index.ts index 0ab02c523..abb53556e 100644 --- a/src/app/features/settings/general/index.ts +++ b/src/app/features/settings/general/index.ts @@ -1 +1,2 @@ export * from './General'; +export * from './LanguageSpecificPronouns'; \ No newline at end of file diff --git a/src/app/hooks/useClientConfig.ts b/src/app/hooks/useClientConfig.ts index deaf6dc18..04593ad65 100644 --- a/src/app/hooks/useClientConfig.ts +++ b/src/app/hooks/useClientConfig.ts @@ -13,6 +13,11 @@ export type ClientConfig = { disableAccountSwitcher?: boolean; + languageSpecificPronouns?: { + enabled?: boolean; + languages?: string[]; + }; + pushNotificationDetails?: { pushNotifyUrl?: string; vapidPublicKey?: string;