Skip to content

Commit

Permalink
Confirm before closing in case of unsaved changes
Browse files Browse the repository at this point in the history
Solve issue #10
  • Loading branch information
imdj committed Jan 24, 2025
1 parent 388b884 commit 9bbc176
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib/components/toolbar/ToolBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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",
Expand Down Expand Up @@ -115,6 +122,7 @@
a.href = url;
a.download = "feeds.opml";
a.click();
opml.lastSaved = new Date().getTime();
URL.revokeObjectURL(url);
}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/opml.svelte.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 9bbc176

Please sign in to comment.