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

Clean up redaction layer between routes #971

Merged
merged 5 commits into from
Dec 12, 2024
Merged
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
3 changes: 2 additions & 1 deletion src/langs/json/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@
"instructions": "Click and drag to draw a black rectangle over each portion of the document you’d like to redact. Associated text will be removed when you save your redactions.",
"undo": "Undo",
"cancel": "Discard",
"cancelWarning": "You will lose unsaved redactions. Are you sure you want to cancel?",
"cancelWarning": "You will lose unsaved redactions. Are you sure you want to discard?",
"leaveWarning": "You have unsaved redactions. Are you sure you want to leave?",
"success": "Redactions saved",
"error": "Error"
},
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/forms/ConfirmRedaction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This almost certainly lives in a modal.
if (result.type === "success") {
// need to invalidate before navigating
await invalidate(`document:${document.id}`);
$redactions = [];
$pending = result.data.redactions;
goto("?mode=document");
dispatch("close");
Expand Down
24 changes: 24 additions & 0 deletions src/lib/components/viewer/RedactionLayer.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<!-- @component
This is a box to draw redactions on.
It's layered over a PDF page and allows us to render redactions and draw new ones.
When saved, redactions are burned into the PDF.
So this layer is only showing unsaved redactions.
-->
<script context="module" lang="ts">
import type { Redaction, Nullable } from "$lib/api/types";
Expand All @@ -26,10 +28,15 @@ It's layered over a PDF page and allows us to render redactions and draw new one

export function clear() {
redactions.set([]);
pending.set([]);
}
</script>

<script lang="ts">
import { onMount } from "svelte";
import { _ } from "svelte-i18n";
import { beforeNavigate } from "$app/navigation";

export let active = false;
export let page_number: number; // 0-indexed

Expand Down Expand Up @@ -99,6 +106,23 @@ It's layered over a PDF page and allows us to render redactions and draw new one
$redactions = [...$redactions, currentRedaction];
currentRedaction = null;
}

beforeNavigate(({ cancel }) => {
if ($redactions.length > 0) {
if (!confirm($_("redact.leaveWarning"))) {
cancel();
return;
}
clear();
}
});

onMount(() => {
// before unmounting the component, clear the current redactions
return () => {
clear();
};
});
</script>

<div
Expand Down
Loading