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:
@@ -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 />
|
||||
Reference in New Issue
Block a user