Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show confirmation when navigating away from in-progress upload form #1001

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/langs/json/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"tesseract": "<a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://tesseract-ocr.github.io/tessdoc/\">Tesseract</a> is an open source OCR engine available free to all DocumentCloud accounts.",
"textract": "<a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://aws.amazon.com/textract/\">Textract</a> is a more powerful OCR engine that can better handle messy text, handwriting and fuzzy scans.",
"empty": "Get started by selecting, pasting or dragging-and-dropping files",
"confirmLeave": "Your upload is not complete. Are you sure you want to leave the page?",
"steps": {
"ready": "Ready",
"created": "Created",
Expand Down
9 changes: 9 additions & 0 deletions src/lib/components/forms/DocumentUpload.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ progress through the three-part upload process.

import { filesize } from "filesize";
import { onMount } from "svelte";
import { beforeNavigate } from "$app/navigation";
import { _ } from "svelte-i18n";
import { Paperclip16, Paperclip24, Upload16 } from "svelte-octicons";

Expand Down Expand Up @@ -139,6 +140,14 @@ progress through the three-part upload process.
addFiles(getFilesToUpload());
});

beforeNavigate((navigation) => {
if (!empty && !loading) {
if (!window.confirm($_("uploadDialog.confirmLeave"))) {
navigation.cancel();
}
}
});

function uniqueId(): string {
// random enough for a small set
return Math.random().toString(32).slice(2);
Expand Down
Loading