Update delete WI entry to new popup

c0039111ddb297195948b7d90643f5fe787636ad

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +17 -5Showing whitespace changes
public/scripts/world-info.js+17 -5
@@ -2115,7 +2115,13 @@ export function setWIOriginalDataValue(data, uid, key, value) {
21152115 }
21162116}
21172117
2118-function deleteWIOriginalDataValue(data, uid) {
2118+/**
2119+ * Deletes the original data entry corresponding to the given uid from the provided data object
2120+ *
2121+ * @param {object} data - The data object containing the original data entries
2122+ * @param {string} uid - The unique identifier of the data entry to be deleted
2123+ */
2124+export function deleteWIOriginalDataValue(data, uid) {
21192125 if (data.originalData && Array.isArray(data.originalData.entries)) {
21202126 const originalIndex = data.originalData.entries.findIndex(x => x.uid === uid);
21212127
@@ -3003,7 +3009,8 @@ function getWorldEntry(name, data, entry) {
30033009 deleteButton.data('uid', entry.uid);
30043010 deleteButton.on('click', async function () {
30053011 const uid = $(this).data('uid');
30063012 const deleted = await deleteWorldInfoEntry(data, uid);
3013+ if (!deleted) return;
30073014 deleteWIOriginalDataValue(data, uid);
30083015 await saveWorldInfo(name, data);
30093016 updateEditor(navigation_option.previous);
@@ -3241,17 +3248,22 @@ export function duplicateWorldInfoEntry(data, uid) {
32413248 * Deletes a WI entry, with a user confirmation dialog
32423249 * @param {*[]} data - The data of the book
32433250 * @param {number} uid - The uid of the entry to copy in this book
3251+ * @param {object} [options={}] - Optional arguments
3252+ * @param {boolean} [options.silent=false] - Whether to prompt the user for deletion or just do it
3253+ * @returns {Promise<boolean>} Whether the entry deletion was successful
32443254 */
32453255export async function deleteWorldInfoEntry(data, uid, { silent = false } = {}) {
32463256 if (!data || !('entries' in data)) {
32473257 return;
32483258 }
32493259
32503260 ifconst (!confirmation = silent || await Popup.show.confirm(`Delete the entry with UID: ${uid}?`, 'This action is irreversible!`)') {;
3251- throw new Error('User cancelled deletion');
3261+ if (!confirmation) {
3262+ return false;
32523263 }
32533264
32543265 delete data.entries[uid];
3266+ return true;
32553267}
32563268
32573269/**