Skip to content

Commit 05dddb7

Browse files
committed
remove automatic title if it was from a video that was removed in upload dialog
1 parent bbd15f6 commit 05dddb7

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

app/components/dialogs/upload-video-dialog.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ import {
2424
humanFileSize,
2525
notNanOrDefault,
2626
} from "@/lib/utils";
27-
import { Progress } from "../ui/progress";
2827
import { FFmpeg } from "@ffmpeg/ffmpeg";
2928
import { fetchFile, toBlobURL } from "@ffmpeg/util";
3029
import { RangeSlider } from "../ui/range-slider";
31-
import { toast } from "sonner";
3230

3331
type FormData = {
3432
title: string | null;
@@ -113,10 +111,7 @@ function UploadVideoDialogChild() {
113111
form.validateField("file", "change");
114112

115113
if (file?.name && form.state.values.title === null) {
116-
form.setFieldValue(
117-
"title",
118-
file.name.split(".").slice(0, -1).join(".").slice(0, 100)
119-
);
114+
form.setFieldValue("title", getVideoTitleFromFile(file));
120115
}
121116
}
122117

@@ -212,7 +207,6 @@ function UploadVideoDialogChild() {
212207
name="file"
213208
validators={{
214209
onChange: ({ value }) => {
215-
console.log(value);
216210
if (!value) {
217211
return "File is required";
218212
}
@@ -301,6 +295,17 @@ function UploadVideoDialogChild() {
301295
if (fileInputRef.current) {
302296
fileInputRef.current.value = "";
303297
}
298+
299+
if (
300+
form.state.values.file &&
301+
form.state.values.title ===
302+
getVideoTitleFromFile(
303+
form.state.values.file
304+
)
305+
) {
306+
form.setFieldValue("title", null);
307+
}
308+
304309
handleFileChange(null);
305310
}}
306311
className="bg-zinc-800 text-zinc-200 border-zinc-700 hover:bg-zinc-700 hover:text-white"
@@ -635,3 +640,12 @@ function TrimVideoDialog({
635640
</Dialog>
636641
);
637642
}
643+
644+
/**
645+
* Extracts a title from a video file name by removing the extension and truncating to 100 characters
646+
* @param {File} file - The video file to get the title from
647+
* @returns The extracted title, truncated to 100 characters
648+
*/
649+
function getVideoTitleFromFile(file: File) {
650+
return file.name.split(".").slice(0, -1).join(".").slice(0, 100);
651+
}

0 commit comments

Comments
 (0)