1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-29 16:07:40 +01:00

Make download subtitle not automatically crash the tab but only after clicking (if ram is too low)

This commit is contained in:
mrjvs 2024-01-24 15:13:59 +01:00
parent 392c60a9f9
commit a87f4cf222

View file

@ -1,4 +1,4 @@
import { useMemo } from "react"; import { useCallback, useMemo } from "react";
import { Trans, useTranslation } from "react-i18next"; import { Trans, useTranslation } from "react-i18next";
import { Button } from "@/components/buttons/Button"; import { Button } from "@/components/buttons/Button";
@ -46,13 +46,13 @@ export function DownloadView({ id }: { id: string }) {
const sourceType = usePlayerStore((s) => s.source?.type); const sourceType = usePlayerStore((s) => s.source?.type);
const selectedCaption = usePlayerStore((s) => s.caption?.selected); const selectedCaption = usePlayerStore((s) => s.caption?.selected);
const subtitleUrl = useMemo( const openSubtitleDownload = useCallback(() => {
() => const dataUrl = selectedCaption
selectedCaption
? convertSubtitlesToSrtDataurl(selectedCaption?.srtData) ? convertSubtitlesToSrtDataurl(selectedCaption?.srtData)
: null, : null;
[selectedCaption], if (!dataUrl) return;
); window.open(dataUrl);
}, [selectedCaption]);
if (!downloadUrl) return null; if (!downloadUrl) return null;
@ -74,10 +74,9 @@ export function DownloadView({ id }: { id: string }) {
</Button> </Button>
<Button <Button
className="w-full mt-2" className="w-full mt-2"
href={subtitleUrl ?? undefined} onClick={openSubtitleDownload}
disabled={!subtitleUrl} disabled={!selectedCaption}
theme="secondary" theme="secondary"
download="subtitles.srt"
> >
{t("player.menus.downloads.downloadSubtitle")} {t("player.menus.downloads.downloadSubtitle")}
</Button> </Button>
@ -109,8 +108,8 @@ export function DownloadView({ id }: { id: string }) {
</Button> </Button>
<Button <Button
className="w-full mt-2" className="w-full mt-2"
href={subtitleUrl ?? undefined} onClick={openSubtitleDownload}
disabled={!subtitleUrl} disabled={!selectedCaption}
theme="secondary" theme="secondary"
download="subtitles.srt" download="subtitles.srt"
> >