feat: trigger confirm with unsaved changes (#378)

* trigger confirm with unsaved changes

* feat: add warning banner to course settings

* feat: implement on settings page.

* rename
This commit is contained in:
Rotimi Best
2024-11-20 10:33:28 +01:00
committed by GitHub
parent dc9e00a7ae
commit 02571e5ea7
3 changed files with 11022 additions and 12137 deletions
@@ -0,0 +1,24 @@
<script lang="ts">
import { beforeNavigate } from '$app/navigation';
export let hasUnsavedChanges = false;
export let message = 'You have unsaved changes. Are you sure you want to leave?';
beforeNavigate(({ cancel }) => {
if (!shouldAbandonChanges()) cancel();
});
function shouldAbandonChanges() {
if (!hasUnsavedChanges) return true;
return confirm(message);
}
</script>
<svelte:window
on:beforeunload={(e) => {
const result = shouldAbandonChanges();
if (!result) e.preventDefault();
}}
/>
<slot />