diff --git a/src/lib/components/toolbar/ToolBar.svelte b/src/lib/components/toolbar/ToolBar.svelte index cad3d13..4d6e2f3 100644 --- a/src/lib/components/toolbar/ToolBar.svelte +++ b/src/lib/components/toolbar/ToolBar.svelte @@ -7,6 +7,7 @@ import {viewMode} from "$lib/opml.svelte.js"; import FeedModal from "$lib/components/modals/FeedModal.svelte"; import AttributesModal from "$lib/components/modals/AttributesModal.svelte"; + import { beforeNavigate } from '$app/navigation'; let { view = $bindable() } = $props() @@ -26,6 +27,12 @@ window.removeEventListener('keyup', handleShortcuts); }); + beforeNavigate((navigation) => { + if (opml.lastSaved < opml.lastModified && navigation.type === 'leave') { + navigation.cancel(); + } + }); + let FileMenu = [ { name: "Open file", @@ -115,6 +122,7 @@ a.href = url; a.download = "feeds.opml"; a.click(); + opml.lastSaved = new Date().getTime(); URL.revokeObjectURL(url); } diff --git a/src/lib/opml.svelte.js b/src/lib/opml.svelte.js index 6a73d06..09dc83c 100644 --- a/src/lib/opml.svelte.js +++ b/src/lib/opml.svelte.js @@ -102,12 +102,15 @@ export class opmlDoc { outlineMap = $state(new SvelteMap()); selectedItems = $state(new SvelteSet()); numOfFeeds = $derived(Array.from(this.outlineMap.values()).reduce((acc, outline) => acc + outline.attributes.has("xmlUrl"), 0)); + lastSaved = $state(new Date().getTime()); + lastModified = $state(new Date().getTime()); // private to avoid recursive updates _rawContent = $state(""); set rawContent(value) { this._rawContent = value; + this.lastModified = new Date().getTime(); this.debounceParse(value); }