From 26ce9d73e6b6c4cc1e219deba722c0eaab4b3187 Mon Sep 17 00:00:00 2001 From: Anderson Shindy Oki Date: Tue, 25 Jun 2024 11:11:08 +0900 Subject: [PATCH] Fixed frontend sync and translate missing hi and forced information --- frontend/src/components/SubtitleToolsMenu.tsx | 2 ++ .../src/components/forms/SyncSubtitleForm.tsx | 14 ++++++++--- frontend/src/pages/Episodes/components.tsx | 5 +++- frontend/src/pages/Movies/Details/table.tsx | 6 +++-- frontend/src/utilities/index.test.ts | 25 +++++++++++++++++++ frontend/src/utilities/index.ts | 4 +++ 6 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 frontend/src/utilities/index.test.ts diff --git a/frontend/src/components/SubtitleToolsMenu.tsx b/frontend/src/components/SubtitleToolsMenu.tsx index ce7770e16..545c87478 100644 --- a/frontend/src/components/SubtitleToolsMenu.tsx +++ b/frontend/src/components/SubtitleToolsMenu.tsx @@ -127,6 +127,8 @@ const SubtitleToolsMenu: FunctionComponent = ({ type: s.type, language: s.language, path: s.path, + hi: s.hi, + forced: s.forced, }; task.create(s.path, name, mutateAsync, { action, form }); }); diff --git a/frontend/src/components/forms/SyncSubtitleForm.tsx b/frontend/src/components/forms/SyncSubtitleForm.tsx index f55b3ddb8..63953fb2d 100644 --- a/frontend/src/components/forms/SyncSubtitleForm.tsx +++ b/frontend/src/components/forms/SyncSubtitleForm.tsx @@ -17,7 +17,7 @@ import { import { useModals, withModal } from "@/modules/modals"; import { task } from "@/modules/task"; import { syncMaxOffsetSecondsOptions } from "@/pages/Settings/Subtitles/options"; -import { toPython } from "@/utilities"; +import { fromPython, toPython } from "@/utilities"; const TaskName = "Syncing Subtitle"; @@ -109,6 +109,8 @@ interface FormValues { maxOffsetSeconds?: string; noFixFramerate: boolean; gss: boolean; + hi?: boolean; + forced?: boolean; } const SyncSubtitleForm: FunctionComponent = ({ @@ -122,9 +124,11 @@ const SyncSubtitleForm: FunctionComponent = ({ const { mutateAsync } = useSubtitleAction(); const modals = useModals(); - const mediaType = selections[0].type; - const mediaId = selections[0].id; - const subtitlesPath = selections[0].path; + const subtitle = selections[0]; + + const mediaType = subtitle.type; + const mediaId = subtitle.id; + const subtitlesPath = subtitle.path; const subtitles = useReferencedSubtitles(mediaType, mediaId, subtitlesPath); @@ -132,6 +136,8 @@ const SyncSubtitleForm: FunctionComponent = ({ initialValues: { noFixFramerate: false, gss: false, + hi: fromPython(subtitle.hi), + forced: fromPython(subtitle.forced), }, }); diff --git a/frontend/src/pages/Episodes/components.tsx b/frontend/src/pages/Episodes/components.tsx index 98bf15ecd..7b21393fa 100644 --- a/frontend/src/pages/Episodes/components.tsx +++ b/frontend/src/pages/Episodes/components.tsx @@ -4,6 +4,7 @@ import { useEpisodeSubtitleModification } from "@/apis/hooks"; import Language from "@/components/bazarr/Language"; import SubtitleToolsMenu from "@/components/SubtitleToolsMenu"; import { task, TaskGroup } from "@/modules/task"; +import { toPython } from "@/utilities"; interface Props { seriesId: number; @@ -43,11 +44,13 @@ export const Subtitle: FunctionComponent = ({ type: "episode", language: subtitle.code2, path: subtitle.path, + forced: toPython(subtitle.forced), + hi: toPython(subtitle.hi), }); } return list; - }, [episodeId, subtitle.code2, subtitle.path]); + }, [episodeId, subtitle.code2, subtitle.path, subtitle.forced, subtitle.hi]); const ctx = ( diff --git a/frontend/src/pages/Movies/Details/table.tsx b/frontend/src/pages/Movies/Details/table.tsx index eef5a52f6..03593102c 100644 --- a/frontend/src/pages/Movies/Details/table.tsx +++ b/frontend/src/pages/Movies/Details/table.tsx @@ -9,7 +9,7 @@ import { Action, SimpleTable } from "@/components"; import Language from "@/components/bazarr/Language"; import SubtitleToolsMenu from "@/components/SubtitleToolsMenu"; import { task, TaskGroup } from "@/modules/task"; -import { filterSubtitleBy } from "@/utilities"; +import { filterSubtitleBy, toPython } from "@/utilities"; import { useProfileItemsToLanguages } from "@/utilities/languages"; const missingText = "Missing Subtitles"; @@ -95,11 +95,13 @@ const Table: FunctionComponent = ({ movie, profile, disabled }) => { path, id: movie.radarrId, language: code2, + forced: toPython(forced), + hi: toPython(hi), }); } return list; - }, [code2, path]); + }, [code2, path, forced, hi]); if (movie === null) { return null; diff --git a/frontend/src/utilities/index.test.ts b/frontend/src/utilities/index.test.ts new file mode 100644 index 000000000..b2596a005 --- /dev/null +++ b/frontend/src/utilities/index.test.ts @@ -0,0 +1,25 @@ +import { fromPython, toPython } from "@/utilities/index"; + +describe("fromPythonConversion", () => { + it("should convert a true value", () => { + expect(fromPython("True")).toBe(true); + }); + + it("should convert a false value", () => { + expect(fromPython("False")).toBe(false); + }); + + it("should convert an undefined value", () => { + expect(fromPython(undefined)).toBe(false); + }); +}); + +describe("toPythonConversion", () => { + it("should convert a true value", () => { + expect(toPython(true)).toBe("True"); + }); + + it("should convert a false value", () => { + expect(toPython(false)).toBe("False"); + }); +}); diff --git a/frontend/src/utilities/index.ts b/frontend/src/utilities/index.ts index f8b9d1961..cde66d894 100644 --- a/frontend/src/utilities/index.ts +++ b/frontend/src/utilities/index.ts @@ -59,6 +59,10 @@ export function filterSubtitleBy( } } +export function fromPython(value: PythonBoolean | undefined): boolean { + return value === "True"; +} + export function toPython(value: boolean): PythonBoolean { return value ? "True" : "False"; }