From a49a34f1320ac2bdbec51df244494d148721c2c3 Mon Sep 17 00:00:00 2001 From: "DESKTOP-C9V2M01\\Zeeri" Date: Wed, 15 Jun 2022 11:46:14 -0700 Subject: [PATCH] Created a dirty site variable and cloned the edited site. Fixes the focus bug and prevents unsaved changes from appearing in the table after cancelling the editor. --- imports/ui/Admin.svelte | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/imports/ui/Admin.svelte b/imports/ui/Admin.svelte index cfda532..00c9869 100644 --- a/imports/ui/Admin.svelte +++ b/imports/ui/Admin.svelte @@ -48,14 +48,19 @@ const deleteSite = site => { //TODO: }; + // Create a holder for the site being edited. This allows us to clear the editor when the user finishes, and allows the table or parent view to setup the editor. let editedSite = writable(null); + let dirtySite = null; + // Copy the edited site when ever it changes, set some defaults for a new site object (to make the view happy). + editedSite.subscribe(site => {dirtySite = Object.assign({name: ""}, site)}); + // Load the sites (reactive). let sites = Sites.find({}); const applySiteChanges = () => { - if($editedSite._id) - Meteor.call("sites.update", $editedSite._id,$editedSite.name); + if(dirtySite._id) + Meteor.call("sites.update", dirtySite._id, dirtySite.name); else - Meteor.call("sites.add", $editedSite.name); + Meteor.call("sites.add", dirtySite.name); editedSite.set(null); } const rejectSiteChanges = () => { @@ -65,10 +70,10 @@
- {#if $editedSite} + {#if dirtySite}
- + Provide a unique name for the site.