Skip to content

Commit

Permalink
Merge pull request #971 from MuckRock/allanlasser/issue968
Browse files Browse the repository at this point in the history
Clean up redaction layer between routes
  • Loading branch information
allanlasser authored Dec 12, 2024
2 parents 9a61b20 + c014890 commit 9caf00f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
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 @@ -103,6 +110,23 @@ It's layered over a PDF page and allows us to render redactions and draw new one
drawStart = null;
drawing = false;
}
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

0 comments on commit 9caf00f

Please sign in to comment.