Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed upload subtitle language selection duplicated languages #2673

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 24 additions & 47 deletions frontend/src/components/forms/MovieUploadForm.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { FunctionComponent, useEffect, useMemo } from "react";
import {
Button,
Checkbox,
Divider,
MantineColor,
Stack,
Text,
} from "@mantine/core";
import { Button, Divider, MantineColor, Stack, Text } from "@mantine/core";
import { useForm } from "@mantine/form";
import {
faCheck,
Expand All @@ -17,14 +10,14 @@ import {
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { ColumnDef } from "@tanstack/react-table";
import { isString } from "lodash";
import { cond, isString, uniqWith } from "lodash";
import { useMovieSubtitleModification } from "@/apis/hooks";
import { Action, Selector } from "@/components/inputs";
import SimpleTable from "@/components/tables/SimpleTable";
import TextPopover from "@/components/TextPopover";
import { useModals, withModal } from "@/modules/modals";
import { task, TaskGroup } from "@/modules/task";
import { useArrayAction, useSelectorOptions } from "@/utilities";
import { BuildKey, useArrayAction, useSelectorOptions } from "@/utilities";
import FormUtils from "@/utilities/form";
import {
useLanguageProfileBy,
Expand All @@ -34,8 +27,6 @@ import {
type SubtitleFile = {
file: File;
language: Language.Info | null;
forced: boolean;
hi: boolean;
validateResult?: SubtitleValidateResult;
};

Expand Down Expand Up @@ -88,9 +79,20 @@ const MovieUploadForm: FunctionComponent<Props> = ({

const languages = useProfileItemsToLanguages(profile);
const languageOptions = useSelectorOptions(
languages,
(v) => v.name,
(v) => v.code2,
uniqWith(
languages,
(a, b) => a.code2 === b.code2 && a.hi === b.hi && a.forced === b.forced,
),
(v) => {
const suffix = cond([
[(v: Language.Info) => v.hi || false, () => "(Hearing Impaired Only)"],
[(v) => v.forced || false, () => "(Forced Only)"],
[() => true, () => "(Normal or Hearing Impaired)"],
]);

return `${v.name} ${suffix(v)}`;
},
(v) => BuildKey(v.code2, v.hi, v.forced),
Comment on lines +82 to +95
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead we should replace it with 2 dropdowns.

);

const defaultLanguage = useMemo(
Expand All @@ -104,8 +106,6 @@ const MovieUploadForm: FunctionComponent<Props> = ({
.map<SubtitleFile>((file) => ({
file,
language: defaultLanguage,
forced: defaultLanguage?.forced ?? false,
hi: defaultLanguage?.hi ?? false,
}))
.map<SubtitleFile>((v) => ({
...v,
Expand Down Expand Up @@ -207,34 +207,6 @@ const MovieUploadForm: FunctionComponent<Props> = ({
return <Text className="table-primary">{file.name}</Text>;
},
},
{
header: "Forced",
accessorKey: "forced",
cell: ({ row: { original, index } }) => {
return (
<Checkbox
checked={original.forced}
onChange={({ currentTarget: { checked } }) => {
action.mutate(index, { ...original, forced: checked });
}}
></Checkbox>
);
},
},
{
header: "HI",
accessorKey: "hi",
cell: ({ row: { original, index } }) => {
return (
<Checkbox
checked={original.hi}
onChange={({ currentTarget: { checked } }) => {
action.mutate(index, { ...original, hi: checked });
}}
></Checkbox>
);
},
},
{
header: "Language",
accessorKey: "language",
Expand Down Expand Up @@ -275,14 +247,19 @@ const MovieUploadForm: FunctionComponent<Props> = ({
onSubmit={form.onSubmit(({ files }) => {
const { radarrId } = movie;

files.forEach(({ file, language, hi, forced }) => {
files.forEach(({ file, language }) => {
if (language === null) {
throw new Error("Language is not selected");
}

task.create(file.name, TaskGroup.UploadSubtitle, upload.mutateAsync, {
radarrId,
form: { file, language: language.code2, hi, forced },
form: {
file,
language: language.code2,
hi: language.hi || false,
forced: language.forced || false,
},
});
});

Expand Down
72 changes: 20 additions & 52 deletions frontend/src/components/forms/SeriesUploadForm.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { FunctionComponent, useEffect, useMemo } from "react";
import {
Button,
Checkbox,
Divider,
MantineColor,
Stack,
Text,
} from "@mantine/core";
import { Button, Divider, MantineColor, Stack, Text } from "@mantine/core";
import { useForm } from "@mantine/form";
import {
faCheck,
Expand All @@ -17,7 +10,7 @@ import {
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { ColumnDef } from "@tanstack/react-table";
import { isString } from "lodash";
import { cond, isString, uniqWith } from "lodash";
import {
useEpisodesBySeriesId,
useEpisodeSubtitleModification,
Expand All @@ -28,7 +21,7 @@ import SimpleTable from "@/components/tables/SimpleTable";
import TextPopover from "@/components/TextPopover";
import { useModals, withModal } from "@/modules/modals";
import { task, TaskGroup } from "@/modules/task";
import { useArrayAction, useSelectorOptions } from "@/utilities";
import { BuildKey, useArrayAction, useSelectorOptions } from "@/utilities";
import FormUtils from "@/utilities/form";
import {
useLanguageProfileBy,
Expand Down Expand Up @@ -100,9 +93,20 @@ const SeriesUploadForm: FunctionComponent<Props> = ({
const profile = useLanguageProfileBy(series.profileId);
const languages = useProfileItemsToLanguages(profile);
const languageOptions = useSelectorOptions(
languages,
(v) => v.name,
(v) => v.code2,
uniqWith(
languages,
(a, b) => a.code2 === b.code2 && a.hi === b.hi && a.forced === b.forced,
),
(v) => {
const suffix = cond([
[(v: Language.Info) => v.hi || false, () => "(Hearing Impaired Only)"],
[(v) => v.forced || false, () => "(Forced Only)"],
[() => true, () => "(Normal or Hearing Impaired)"],
]);

return `${v.name} ${suffix(v)}`;
},
(v) => BuildKey(v.code2, v.hi, v.forced),
);

const defaultLanguage = useMemo(
Expand Down Expand Up @@ -235,42 +239,6 @@ const SeriesUploadForm: FunctionComponent<Props> = ({
return <Text className="table-primary">{name}</Text>;
},
},
{
header: "Forced",
accessorKey: "forced",
cell: ({ row: { original, index } }) => {
return (
<Checkbox
checked={original.forced}
onChange={({ currentTarget: { checked } }) => {
action.mutate(index, {
...original,
forced: checked,
hi: checked ? false : original.hi,
});
}}
></Checkbox>
);
},
},
{
header: "HI",
accessorKey: "hi",
cell: ({ row: { original, index } }) => {
return (
<Checkbox
checked={original.hi}
onChange={({ currentTarget: { checked } }) => {
action.mutate(index, {
...original,
hi: checked,
forced: checked ? false : original.forced,
});
}}
></Checkbox>
);
},
},
{
header: () => (
<Selector
Expand Down Expand Up @@ -344,7 +312,7 @@ const SeriesUploadForm: FunctionComponent<Props> = ({
const { sonarrSeriesId: seriesId } = series;

files.forEach((value) => {
const { file, hi, forced, language, episode } = value;
const { file, language, episode } = value;

if (language === null || episode === null) {
throw new Error(
Expand All @@ -361,8 +329,8 @@ const SeriesUploadForm: FunctionComponent<Props> = ({
form: {
file,
language: code2,
hi,
forced,
hi: language.hi || false,
forced: language.forced || false,
},
});
});
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/Movies/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { faBookmark as farBookmark } from "@fortawesome/free-regular-svg-icons";
import { faBookmark, faWrench } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { ColumnDef } from "@tanstack/react-table";
import { uniqueId } from "lodash";
import { useMovieModification, useMoviesPagination } from "@/apis/hooks";
import { Action } from "@/components";
import { AudioList } from "@/components/bazarr";
Expand Down Expand Up @@ -95,7 +96,7 @@ const MovieView: FunctionComponent = () => {
<Badge
mr="xs"
color="yellow"
key={BuildKey(v.code2, v.hi, v.forced)}
key={uniqueId(`${BuildKey(v.code2, v.hi, v.forced)}_`)}
>
<Language.Text value={v}></Language.Text>
</Badge>
Expand Down