From 192692d96b90d1e6254e83fe672a5650f9404f58 Mon Sep 17 00:00:00 2001 From: Neil Brommer Date: Wed, 27 Dec 2017 16:01:12 -0800 Subject: [PATCH] Better handle group indexes when deleting a group --- js/editBookmarks.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/js/editBookmarks.js b/js/editBookmarks.js index a7e8a12..5dcd08a 100644 --- a/js/editBookmarks.js +++ b/js/editBookmarks.js @@ -80,9 +80,21 @@ function deleteGroup(e) { var db = dbe.target.result; var groupsStore = db.transaction("Groups", "readwrite").objectStore("Groups"); - var delReq = groupsStore.delete(groupIndex); - delReq.onsuccess = function (dele) { - $("#group-" + groupIndex).remove(); + + groupsStore.getAll().onsuccess = function (getEvt) { + var groups = getEvt.target.result; + + var lastIndex = -1; + for (item of groups) { + if (item.groupIndex > groupIndex) { + lastIndex = item.groupIndex; + item.groupIndex--; + groupsStore.put(item); + } + } + + groupsStore.delete(lastIndex); + loadBookmarks(); } }