Skip to content

armgit / VERT

Public Imported from GitHub
0

The next-generation file converter. Open source, fully local* and free forever.

fix: dragging and dropping files sometimes not navigating to conversion page

JovannMCe7973d717dfc
diff --git a/src/lib/store/index.svelte.ts b/src/lib/store/index.svelte.ts
index f273f0a..8d0ef4e 100644
--- a/src/lib/store/index.svelte.ts
+++ b/src/lib/store/index.svelte.ts
@@ -391,6 +391,19 @@ class Files {
}
}
+ private addFile(input: VertFile | File): Promise<void> {
+ return this._add(input).catch((err) => {
+ error(["files"], `error adding file ${input.name}: ${err}`);
+ ToastManager.add({
+ type: "error",
+ message: m["workers.errors.general"]({
+ file: input.name,
+ message: String(err),
+ }),
+ });
+ });
+ }
+
public add(file: VertFile | null | undefined): void;
public add(file: File | null | undefined): void;
public add(file: File[] | null | undefined): void;
@@ -401,22 +414,30 @@ class Files {
VertFile | File | VertFile[] | File[] | FileList | null | undefined,
) {
if (!file) return;
- const addFile = (input: VertFile | File) => {
- void this._add(input).catch((err) => {
- error(["files"], `error adding file ${input.name}: ${err}`);
- ToastManager.add({
- type: "error",
- message: m["workers.errors.general"]({
- file: input.name,
- message: String(err),
- }),
- });
- });
- };
if (Array.isArray(file) || file instanceof FileList) {
- for (const f of file) addFile(f);
+ for (const f of file) void this.addFile(f);
+ } else {
+ void this.addFile(file);
+ }
+ }
+
+ // like add(), but resolves once all files have finished being added
+ public addAsync(file: VertFile | null | undefined): Promise<void>;
+ public addAsync(file: File | null | undefined): Promise<void>;
+ public addAsync(file: File[] | null | undefined): Promise<void>;
+ public addAsync(file: VertFile[] | null | undefined): Promise<void>;
+ public addAsync(file: FileList | null | undefined): Promise<void>;
+ public async addAsync(
+ file:
+ VertFile | File | VertFile[] | File[] | FileList | null | undefined,
+ ) {
+ if (!file) return;
+ if (Array.isArray(file)) {
+ await Promise.all(file.map((f) => this.addFile(f)));
+ } else if (file instanceof FileList) {
+ await Promise.all(Array.from(file).map((f) => this.addFile(f)));
} else {
- addFile(file);
+ await this.addFile(file);
}
}
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 6428232..1036cd7 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -45,12 +45,12 @@
window.scrollTo(0, scrollY);
});
- const dropFiles = (e: DragEvent) => {
+ const dropFiles = async (e: DragEvent) => {
e.preventDefault();
dropping.set(false);
const oldLength = files.files.length;
- files.add(e.dataTransfer?.files);
- if (oldLength !== files.files.length) goto("/convert");
+ await files.addAsync(e.dataTransfer?.files);
+ if (files.files.length !== oldLength) goto("/convert");
};
const handleDrag = (e: DragEvent, drag: boolean) => {
@@ -58,13 +58,13 @@
dropping.set(drag);
};
- const handlePaste = (e: ClipboardEvent) => {
+ const handlePaste = async (e: ClipboardEvent) => {
const clipboardData = e.clipboardData;
if (!clipboardData || !clipboardData.files.length) return;
e.preventDefault();
const oldLength = files.files.length;
- files.add(clipboardData.files);
- if (oldLength !== files.files.length) goto("/convert");
+ await files.addAsync(clipboardData.files);
+ if (files.files.length !== oldLength) goto("/convert");
};
onMount(() => {