Skip to content

Commit

Permalink
Merge pull request #1001 from MuckRock/allanlasser/issue983
Browse files Browse the repository at this point in the history
Show confirmation when navigating away from in-progress upload form
  • Loading branch information
allanlasser authored Jan 14, 2025
2 parents d25dd8a + fdfdd95 commit 83473f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
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
10 changes: 10 additions & 0 deletions src/lib/components/forms/DocumentUpload.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ progress through the three-part upload process.
Project,
} from "$lib/api/types";
import { beforeNavigate } from "$app/navigation";
import { filesize } from "filesize";
import { onMount } from "svelte";
import { _ } from "svelte-i18n";
Expand Down Expand Up @@ -139,6 +141,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

0 comments on commit 83473f6

Please sign in to comment.