From a87f4cf22266c28b1743cb4311af1dd942876fb7 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Wed, 24 Jan 2024 15:13:59 +0100 Subject: [PATCH] Make download subtitle not automatically crash the tab but only after clicking (if ram is too low) --- .../player/atoms/settings/Downloads.tsx | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/components/player/atoms/settings/Downloads.tsx b/src/components/player/atoms/settings/Downloads.tsx index bba9cf20..45c97997 100644 --- a/src/components/player/atoms/settings/Downloads.tsx +++ b/src/components/player/atoms/settings/Downloads.tsx @@ -1,4 +1,4 @@ -import { useMemo } from "react"; +import { useCallback, useMemo } from "react"; import { Trans, useTranslation } from "react-i18next"; import { Button } from "@/components/buttons/Button"; @@ -46,13 +46,13 @@ export function DownloadView({ id }: { id: string }) { const sourceType = usePlayerStore((s) => s.source?.type); const selectedCaption = usePlayerStore((s) => s.caption?.selected); - const subtitleUrl = useMemo( - () => - selectedCaption - ? convertSubtitlesToSrtDataurl(selectedCaption?.srtData) - : null, - [selectedCaption], - ); + const openSubtitleDownload = useCallback(() => { + const dataUrl = selectedCaption + ? convertSubtitlesToSrtDataurl(selectedCaption?.srtData) + : null; + if (!dataUrl) return; + window.open(dataUrl); + }, [selectedCaption]); if (!downloadUrl) return null; @@ -74,10 +74,9 @@ export function DownloadView({ id }: { id: string }) { @@ -109,8 +108,8 @@ export function DownloadView({ id }: { id: string }) {