mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-28 23:16:05 +00:00
Make download subtitle not automatically crash the tab but only after clicking (if ram is too low)
This commit is contained in:
parent
392c60a9f9
commit
a87f4cf222
|
@ -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 }) {
|
|||
</Button>
|
||||
<Button
|
||||
className="w-full mt-2"
|
||||
href={subtitleUrl ?? undefined}
|
||||
disabled={!subtitleUrl}
|
||||
onClick={openSubtitleDownload}
|
||||
disabled={!selectedCaption}
|
||||
theme="secondary"
|
||||
download="subtitles.srt"
|
||||
>
|
||||
{t("player.menus.downloads.downloadSubtitle")}
|
||||
</Button>
|
||||
|
@ -109,8 +108,8 @@ export function DownloadView({ id }: { id: string }) {
|
|||
</Button>
|
||||
<Button
|
||||
className="w-full mt-2"
|
||||
href={subtitleUrl ?? undefined}
|
||||
disabled={!subtitleUrl}
|
||||
onClick={openSubtitleDownload}
|
||||
disabled={!selectedCaption}
|
||||
theme="secondary"
|
||||
download="subtitles.srt"
|
||||
>
|
||||
|
|
Loading…
Reference in a new issue