diff options
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/src/components/forms/ProfileEditForm.tsx | 35 | ||||
-rw-r--r-- | frontend/src/pages/Settings/Languages/table.tsx | 18 | ||||
-rw-r--r-- | frontend/src/types/api.d.ts | 2 | ||||
-rw-r--r-- | frontend/src/utilities/languages.ts | 2 |
4 files changed, 25 insertions, 32 deletions
diff --git a/frontend/src/components/forms/ProfileEditForm.tsx b/frontend/src/components/forms/ProfileEditForm.tsx index 0a6471dc5..e994888d2 100644 --- a/frontend/src/components/forms/ProfileEditForm.tsx +++ b/frontend/src/components/forms/ProfileEditForm.tsx @@ -12,7 +12,6 @@ import { } from "@mantine/core"; import { useForm } from "@mantine/form"; import { faTrash } from "@fortawesome/free-solid-svg-icons"; -import { cond } from "lodash"; import { Action, Selector, SelectorOption, SimpleTable } from "@/components"; import ChipInput from "@/components/inputs/ChipInput"; import { useModals, withModal } from "@/modules/modals"; @@ -31,7 +30,7 @@ const defaultCutoffOptions: SelectorOption<Language.ProfileItem>[] = [ // eslint-disable-next-line camelcase audio_exclude: "False", forced: "False", - hi: "also", + hi: "False", language: "any", }, }, @@ -39,16 +38,12 @@ const defaultCutoffOptions: SelectorOption<Language.ProfileItem>[] = [ const subtitlesTypeOptions: SelectorOption<string>[] = [ { - label: "Normal only", - value: "never", - }, - { - label: "Hearing-impaired only", - value: "only", + label: "Normal or hearing-impaired", + value: "normal", }, { - label: "Normal or hearing-impaired", - value: "also", + label: "Hearing-impaired required", + value: "hi", }, { label: "Forced (foreign part only)", @@ -88,14 +83,10 @@ const ProfileEditForm: FunctionComponent<Props> = ({ const itemCutoffOptions = useSelectorOptions( form.values.items, (v) => { - const suffix = cond([ - [(v: { forced: string; hi: string }) => v.hi === "only", () => ":hi"], - [(v) => v.hi === "never", () => ":normal"], - [(v) => v.forced === "True", () => ":forced"], - [() => true, () => ""], - ]); + const suffix = + v.hi === "True" ? ":hi" : v.forced === "True" ? ":forced" : ""; - return v.language + suffix(v); + return v.language + suffix; }, (v) => String(v.id), ); @@ -145,7 +136,7 @@ const ProfileEditForm: FunctionComponent<Props> = ({ language, // eslint-disable-next-line camelcase audio_exclude: "False", - hi: "also", + hi: "False", forced: "False", }; @@ -193,8 +184,10 @@ const ProfileEditForm: FunctionComponent<Props> = ({ const selectValue = useMemo(() => { if (item.forced === "True") { return "forced"; + } else if (item.hi === "True") { + return "hi"; } else { - return item.hi; + return "normal"; } }, [item.forced, item.hi]); @@ -206,9 +199,9 @@ const ProfileEditForm: FunctionComponent<Props> = ({ if (value) { action.mutate(index, { ...item, - hi: value, + hi: value === "hi" ? "True" : "False", forced: value === "forced" ? "True" : "False", - } as Language.ProfileItem); + }); } }} ></Select> diff --git a/frontend/src/pages/Settings/Languages/table.tsx b/frontend/src/pages/Settings/Languages/table.tsx index 29902a546..c2ed9d968 100644 --- a/frontend/src/pages/Settings/Languages/table.tsx +++ b/frontend/src/pages/Settings/Languages/table.tsx @@ -2,7 +2,7 @@ import { FunctionComponent, useCallback, useMemo } from "react"; import { Column } from "react-table"; import { Badge, Button, Group } from "@mantine/core"; import { faTrash, faWrench } from "@fortawesome/free-solid-svg-icons"; -import { cloneDeep, cond } from "lodash"; +import { cloneDeep } from "lodash"; import { Action, SimpleTable } from "@/components"; import { anyCutoff, @@ -194,14 +194,14 @@ interface ItemProps { const ItemBadge: FunctionComponent<ItemProps> = ({ cutoff, item }) => { const text = useMemo(() => { - const suffix = cond([ - [(v: { forced: string; hi: string }) => v.hi === "only", () => ":HI"], - [(v) => v.hi === "never", () => ":Normal"], - [(v) => v.forced === "True", () => ":Forced"], - [() => true, () => ""], - ]); - return item.language + suffix(item); - }, [item]); + let result = item.language; + if (item.hi === "True") { + result += ":HI"; + } else if (item.forced === "True") { + result += ":Forced"; + } + return result; + }, [item.hi, item.forced, item.language]); return ( <Badge title={cutoff ? "Ignore others if this one is available" : undefined} diff --git a/frontend/src/types/api.d.ts b/frontend/src/types/api.d.ts index 0d6ba81b9..069be3029 100644 --- a/frontend/src/types/api.d.ts +++ b/frontend/src/types/api.d.ts @@ -28,7 +28,7 @@ declare namespace Language { id: number; audio_exclude: PythonBoolean; forced: PythonBoolean; - hi: "never" | "also" | "only"; + hi: PythonBoolean; language: CodeType; } diff --git a/frontend/src/utilities/languages.ts b/frontend/src/utilities/languages.ts index f9504abf6..1b59aa4e7 100644 --- a/frontend/src/utilities/languages.ts +++ b/frontend/src/utilities/languages.ts @@ -33,7 +33,7 @@ export function useProfileItemsToLanguages(profile?: Language.Profile) { profile?.items.map<Language.Info>(({ language: code, hi, forced }) => { const name = data?.find((v) => v.code2 === code)?.name ?? ""; return { - hi: hi === "only", + hi: hi === "True", forced: forced === "True", code2: code, name, |