import { Action, Selector, SelectorOption, SimpleTable } from "@/components"; import { useModals, withModal } from "@/modules/modals"; import { useTableStyles } from "@/styles"; import { useArrayAction, useSelectorOptions } from "@/utilities"; import { faXmark } from "@fortawesome/free-solid-svg-icons"; import { Accordion, Alert, Button, Checkbox, Stack, Switch, Text, TextInput, } from "@mantine/core"; import { useForm } from "@mantine/hooks"; import { FunctionComponent, useCallback, useMemo } from "react"; import { Column } from "react-table"; import ChipInput from "../inputs/ChipInput"; export const anyCutoff = 65535; const defaultCutoffOptions: SelectorOption[] = [ { label: "Any", value: { id: anyCutoff, audio_exclude: "False", forced: "False", hi: "False", language: "any", }, }, ]; interface Props { onComplete?: (profile: Language.Profile) => void; languages: readonly Language.Info[]; profile: Language.Profile; } const ProfileEditForm: FunctionComponent = ({ onComplete, languages, profile, }) => { const modals = useModals(); const form = useForm({ initialValues: profile, validationRules: { name: (value) => value.length > 0, items: (value) => value.length > 0, }, errorMessages: { items: ( Must contain at lease 1 language ), }, }); const languageOptions = useSelectorOptions(languages, (l) => l.name); const itemCutoffOptions = useSelectorOptions( form.values.items, (v) => v.language ); const cutoffOptions = useMemo( () => ({ ...itemCutoffOptions, options: [...itemCutoffOptions.options, ...defaultCutoffOptions], }), [itemCutoffOptions] ); const mustContainOptions = useSelectorOptions( form.values.mustContain, (v) => v ); const mustNotContainOptions = useSelectorOptions( form.values.mustNotContain, (v) => v ); const action = useArrayAction((fn) => { form.setValues((values) => ({ ...values, items: fn(values.items) })); }); const addItem = useCallback(() => { const id = 1 + form.values.items.reduce( (val, item) => Math.max(item.id, val), 0 ); if (languages.length > 0) { const language = languages[0].code2; const item: Language.ProfileItem = { id, language, audio_exclude: "False", hi: "False", forced: "False", }; const list = [...form.values.items, item]; form.setValues((values) => ({ ...values, items: list })); } }, [form, languages]); const columns = useMemo[]>( () => [ { Header: "ID", accessor: "id", }, { Header: "Language", accessor: "language", Cell: ({ value: code, row: { original: item, index } }) => { const language = useMemo( () => languageOptions.options.find((l) => l.value.code2 === code) ?.value ?? null, [code] ); const { classes } = useTableStyles(); return ( { if (value) { item.language = value.code2; action.mutate(index, { ...item, language: value.code2 }); } }} > ); }, }, { Header: "Forced", accessor: "forced", Cell: ({ row: { original: item, index }, value }) => { return ( { action.mutate(index, { ...item, forced: checked ? "True" : "False", hi: checked ? "False" : item.hi, }); }} > ); }, }, { Header: "HI", accessor: "hi", Cell: ({ row: { original: item, index }, value }) => { return ( { action.mutate(index, { ...item, hi: checked ? "True" : "False", forced: checked ? "False" : item.forced, }); }} > ); }, }, { Header: "Exclude Audio", accessor: "audio_exclude", Cell: ({ row: { original: item, index }, value }) => { return ( { action.mutate(index, { ...item, audio_exclude: checked ? "True" : "False", }); }} > ); }, }, { id: "action", accessor: "id", Cell: ({ row }) => { return ( action.remove(row.index)} > ); }, }, ], [action, languageOptions] ); return (
{ onComplete?.(value); modals.closeSelf(); })} > ({ contentInner: { [theme.fn.smallerThan("md")]: { padding: 0, }, }, })} > {form.errors.items} Subtitles release info must include one of those words or they will be excluded from search results (regex supported). Subtitles release info including one of those words (case insensitive) will be excluded from search results (regex supported). Download subtitle file without format conversion
); }; export const ProfileEditModal = withModal( ProfileEditForm, "languages-profile-editor", { title: "Edit Languages Profile", size: "lg", } ); export default ProfileEditForm;