Skip to content

Commit

Permalink
Feat copy fulltext of transcription (#1221)
Browse files Browse the repository at this point in the history
* copy fulltext of transcription

* fix warning

* fix react warning
  • Loading branch information
an-lee authored Dec 2, 2024
1 parent b71f709 commit cf71d48
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
4 changes: 3 additions & 1 deletion enjoy/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -936,5 +936,7 @@
"exit": "Exit",
"layout": "Layout",
"horizontal": "Horizontal",
"vertical": "Vertical"
"vertical": "Vertical",
"copied": "Copied",
"copyFullText": "Copy full text"
}
4 changes: 3 additions & 1 deletion enjoy/src/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -936,5 +936,7 @@
"exit": "退出",
"layout": "布局",
"horizontal": "水平",
"vertical": "垂直"
"vertical": "垂直",
"copied": "已复制",
"copyFullText": "复制全文"
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const MediaRecordings = () => {
#{currentSegmentIndex + 1}/{transcription?.result?.timeline?.length}
</div>
<DropdownMenu>
<DropdownMenuTrigger>
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="sm">
<SquareMenuIcon className="w-5 h-5 text-muted-foreground" />
</Button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext } from "react";
import { forwardRef, useContext } from "react";
import { Button, toast } from "@renderer/components/ui";
import { t } from "i18next";
import {
Expand All @@ -9,7 +9,10 @@ import { AlignmentResult } from "echogarden/dist/api/API.d.js";
import { convertWordIpaToNormal } from "@/utils";
import template from "./transcription.template.html?raw";

export const MediaTranscriptionPrint = () => {
export const MediaTranscriptionPrint = forwardRef<
HTMLButtonElement,
React.ComponentProps<typeof Button>
>((_, ref) => {
const { media, transcription } = useContext(MediaShadowProviderContext);
const { EnjoyApp, learningLanguage, ipaMappings } = useContext(
AppSettingsProviderContext
Expand Down Expand Up @@ -74,8 +77,15 @@ export const MediaTranscriptionPrint = () => {
}

return (
<Button variant="ghost" className="block w-full" onClick={download}>
<Button
ref={ref}
variant="ghost"
className="block w-full"
onClick={download}
>
{t("print")}
</Button>
);
};
});

MediaTranscriptionPrint.displayName = "MediaTranscriptionPrint";
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuItem,
toast,
} from "@renderer/components/ui";
import {
LoaderIcon,
Expand All @@ -30,6 +31,7 @@ import {
TranscriptionEditButton,
} from "@renderer/components";
import { Sentence } from "@renderer/components";
import { useCopyToClipboard } from "@uidotdev/usehooks";

export const MediaTranscription = (props: { display?: boolean }) => {
const { display } = props;
Expand Down Expand Up @@ -58,6 +60,7 @@ export const MediaTranscription = (props: { display?: boolean }) => {
segment: SegmentType;
}[]
>([]);
const [_, copyToClipboard] = useCopyToClipboard();

const fetchSegmentStats = async () => {
if (!media) return;
Expand Down Expand Up @@ -88,6 +91,15 @@ export const MediaTranscription = (props: { display?: boolean }) => {
}, 300);
};

const handleCopyFullText = () => {
if (!transcription?.result) return;
const fullText = (transcription.result as AlignmentResult).timeline
.map((s) => s.text)
.join("\n\n");
copyToClipboard(fullText);
toast.success(t("copied"));
};

useEffect(() => {
if (!transcription?.result) return;

Expand Down Expand Up @@ -168,6 +180,15 @@ export const MediaTranscription = (props: { display?: boolean }) => {
<DropdownMenuItem asChild>
<MediaTranscriptionPrint />
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Button
variant="ghost"
className="block w-full"
onClick={handleCopyFullText}
>
{t("copyFullText")}
</Button>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
Expand Down

0 comments on commit cf71d48

Please sign in to comment.