From 3dd4f2b94a9da10c9d78a74d721673990e33680c Mon Sep 17 00:00:00 2001 From: steve green Date: Wed, 22 May 2024 19:23:51 +0800 Subject: [PATCH] Always make sure that the delete ****** available --- public/scripts/world-info.js | 54 +++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 256821b3f..723ea94c9 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -1057,6 +1057,34 @@ function displayWorldEntries(name, data, navigation = navigation_option.none, fl return; } + // Regardless of whether success is displayed or not. Make sure the delete button is available. + // Do not put this code behind. + $('#world_popup_delete').off('click').on('click', async () => { + const confirmation = await callPopup(`

Delete the World/Lorebook: "${name}"?

This action is irreversible!`, 'confirm'); + + if (!confirmation) { + return; + } + + if (world_info.charLore) { + world_info.charLore.forEach((charLore, index) => { + if (charLore.extraBooks?.includes(name)) { + const tempCharLore = charLore.extraBooks.filter((e) => e !== name); + if (tempCharLore.length === 0) { + world_info.charLore.splice(index, 1); + } else { + charLore.extraBooks = tempCharLore; + } + } + }); + + saveSettingsDebounced(); + } + + // Selected world_info automatically refreshes + await deleteWorldInfo(name); + }); + // Before printing the WI, we check if we should enable/disable search sorting verifyWorldInfoSearchSortRule(); @@ -1225,32 +1253,6 @@ function displayWorldEntries(name, data, navigation = navigation_option.none, fl } }); - $('#world_popup_delete').off('click').on('click', async () => { - const confirmation = await callPopup(`

Delete the World/Lorebook: "${name}"?

This action is irreversible!`, 'confirm'); - - if (!confirmation) { - return; - } - - if (world_info.charLore) { - world_info.charLore.forEach((charLore, index) => { - if (charLore.extraBooks?.includes(name)) { - const tempCharLore = charLore.extraBooks.filter((e) => e !== name); - if (tempCharLore.length === 0) { - world_info.charLore.splice(index, 1); - } else { - charLore.extraBooks = tempCharLore; - } - } - }); - - saveSettingsDebounced(); - } - - // Selected world_info automatically refreshes - await deleteWorldInfo(name); - }); - // Check if a sortable instance exists if (worldEntriesList.sortable('instance') !== undefined) { // Destroy the instance