mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
finish export cancel feature
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState } from "react";
|
import { useState, useRef } from "react";
|
||||||
import { TransitionTopIcon } from "@hugeicons/core-free-icons";
|
import { TransitionTopIcon } from "@hugeicons/core-free-icons";
|
||||||
import { HugeiconsIcon } from "@hugeicons/react";
|
import { HugeiconsIcon } from "@hugeicons/react";
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
|
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
|
||||||
@@ -86,10 +86,12 @@ function ExportPopover({
|
|||||||
const [isExporting, setIsExporting] = useState(false);
|
const [isExporting, setIsExporting] = useState(false);
|
||||||
const [progress, setProgress] = useState(0);
|
const [progress, setProgress] = useState(0);
|
||||||
const [exportResult, setExportResult] = useState<ExportResult | null>(null);
|
const [exportResult, setExportResult] = useState<ExportResult | null>(null);
|
||||||
|
const cancelRequestedRef = useRef(false);
|
||||||
|
|
||||||
const handleExport = async () => {
|
const handleExport = async () => {
|
||||||
if (!activeProject) return;
|
if (!activeProject) return;
|
||||||
|
|
||||||
|
cancelRequestedRef.current = false;
|
||||||
setIsExporting(true);
|
setIsExporting(true);
|
||||||
setProgress(0);
|
setProgress(0);
|
||||||
setExportResult(null);
|
setExportResult(null);
|
||||||
@@ -101,13 +103,18 @@ function ExportPopover({
|
|||||||
fps: activeProject.settings.fps,
|
fps: activeProject.settings.fps,
|
||||||
includeAudio,
|
includeAudio,
|
||||||
onProgress: ({ progress }) => setProgress(progress),
|
onProgress: ({ progress }) => setProgress(progress),
|
||||||
onCancel: () => false, // TODO: add cancel functionality
|
onCancel: () => cancelRequestedRef.current,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
setIsExporting(false);
|
setIsExporting(false);
|
||||||
setExportResult(result);
|
setExportResult(result);
|
||||||
|
|
||||||
|
if (result.cancelled) {
|
||||||
|
setProgress(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (result.success && result.buffer) {
|
if (result.success && result.buffer) {
|
||||||
const mimeType = getExportMimeType({ format });
|
const mimeType = getExportMimeType({ format });
|
||||||
const extension = getExportFileExtension({ format });
|
const extension = getExportFileExtension({ format });
|
||||||
@@ -136,6 +143,10 @@ function ExportPopover({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleCancel = () => {
|
||||||
|
cancelRequestedRef.current = true;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PopoverContent className="bg-background mr-4 flex w-80 flex-col gap-3">
|
<PopoverContent className="bg-background mr-4 flex w-80 flex-col gap-3">
|
||||||
{exportResult && !exportResult.success ? (
|
{exportResult && !exportResult.success ? (
|
||||||
@@ -262,7 +273,7 @@ function ExportPopover({
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="w-full rounded-md"
|
className="w-full rounded-md"
|
||||||
onClick={() => {}}
|
onClick={handleCancel}
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user