From 61700da39ee7ee497ba47ae60e4ba16826626b58 Mon Sep 17 00:00:00 2001 From: an-lee Date: Thu, 27 Jun 2024 20:01:55 +0800 Subject: [PATCH] Improve transcription form (#730) * add collapsible component * hide subtitle upload as default when transcribe * fix typo --- enjoy/package.json | 1 + enjoy/src/i18n/en.json | 3 +- enjoy/src/i18n/zh-CN.json | 3 +- .../transcription-create-form.tsx | 103 +++++++++++------- .../renderer/components/ui/collapsible.tsx | 11 ++ enjoy/src/renderer/components/ui/index.ts | 47 ++++---- yarn.lock | 3 +- 7 files changed, 103 insertions(+), 68 deletions(-) create mode 100644 enjoy/src/renderer/components/ui/collapsible.tsx diff --git a/enjoy/package.json b/enjoy/package.json index 1bbead57..76f00683 100644 --- a/enjoy/package.json +++ b/enjoy/package.json @@ -92,6 +92,7 @@ "@radix-ui/react-alert-dialog": "^1.1.1", "@radix-ui/react-aspect-ratio": "^1.1.0", "@radix-ui/react-avatar": "^1.1.0", + "@radix-ui/react-collapsible": "^1.1.0", "@radix-ui/react-dropdown-menu": "^2.1.1", "@radix-ui/react-hover-card": "^1.1.1", "@radix-ui/react-icons": "^1.3.0", diff --git a/enjoy/src/i18n/en.json b/enjoy/src/i18n/en.json index d0ed3095..384116a1 100644 --- a/enjoy/src/i18n/en.json +++ b/enjoy/src/i18n/en.json @@ -623,5 +623,6 @@ "allLanguages": "All languages", "search": "Search", "noData": "No data", - "selectedFiles": "Selected files" + "selectedFiles": "Selected files", + "moreOptions": "More options" } diff --git a/enjoy/src/i18n/zh-CN.json b/enjoy/src/i18n/zh-CN.json index d8c25059..05ee6785 100644 --- a/enjoy/src/i18n/zh-CN.json +++ b/enjoy/src/i18n/zh-CN.json @@ -623,5 +623,6 @@ "allLanguages": "全部语言", "search": "搜索", "noData": "没有数据", - "selectedFiles": "已选中文件" + "selectedFiles": "已选中文件", + "moreOptions": "更多选项" } diff --git a/enjoy/src/renderer/components/transcriptions/transcription-create-form.tsx b/enjoy/src/renderer/components/transcriptions/transcription-create-form.tsx index 00949623..fabcfa22 100644 --- a/enjoy/src/renderer/components/transcriptions/transcription-create-form.tsx +++ b/enjoy/src/renderer/components/transcriptions/transcription-create-form.tsx @@ -3,11 +3,14 @@ import { AppSettingsProviderContext, } from "@renderer/context"; import { zodResolver } from "@hookform/resolvers/zod"; -import { useContext } from "react"; +import { useContext, useState } from "react"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { Button, + Collapsible, + CollapsibleContent, + CollapsibleTrigger, Form, FormField, FormItem, @@ -26,7 +29,7 @@ import { } from "@renderer/components/ui"; import { t } from "i18next"; import { LANGUAGES } from "@/constants"; -import { LoaderIcon } from "lucide-react"; +import { ChevronDownIcon, ChevronUpIcon, LoaderIcon } from "lucide-react"; import { parseText } from "media-captions"; const transcriptionSchema = z.object({ @@ -51,6 +54,7 @@ export const TranscriptionCreateForm = (props: { } = props; const { learningLanguage } = useContext(AppSettingsProviderContext); const { whisperConfig } = useContext(AISettingsProviderContext); + const [collapsibleOpen, setCollapsibleOpen] = useState(false); const form = useForm>({ resolver: zodResolver(transcriptionSchema), @@ -171,51 +175,66 @@ export const TranscriptionCreateForm = (props: { )} /> - ( - - - {t("uploadTranscriptFile")}({t("optinal")}) - - { - const file = event.target.files[0]; - - if (file) { - parseSubtitle(file) - .then((text) => { - field.onChange(text); - }) - .catch((error) => { - toast.error(error.message); - }); - } else { - field.onChange(""); - } - }} - /> - {field.value != undefined && ( - <> + + + ( + - {t("transcript")} + {t("uploadTranscriptFile")}({t("optinal")}) -