Update delete WI entry to new popup
| @@ -2115,7 +2115,13 @@ export function setWIOriginalDataValue(data, uid, key, value) { | ||
| 2115 | 2115 | } |
| 2116 | 2116 | } |
| 2117 | 2117 | |
| 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) { | |
| 2119 | 2125 | if (data.originalData && Array.isArray(data.originalData.entries)) { |
| 2120 | 2126 | const originalIndex = data.originalData.entries.findIndex(x => x.uid === uid); |
| 2121 | 2127 | |
| @@ -3003,7 +3009,8 @@ function getWorldEntry(name, data, entry) { | ||
| 3003 | 3009 | deleteButton.data('uid', entry.uid); |
| 3004 | 3010 | deleteButton.on('click', async function () { |
| 3005 | 3011 | const uid = $(this).data('uid'); |
| 3006 | 3012 | const deleted = await deleteWorldInfoEntry(data, uid); |
| 3013 | + if (!deleted) return; | |
| 3007 | 3014 | deleteWIOriginalDataValue(data, uid); |
| 3008 | 3015 | await saveWorldInfo(name, data); |
| 3009 | 3016 | updateEditor(navigation_option.previous); |
| @@ -3241,17 +3248,22 @@ export function duplicateWorldInfoEntry(data, uid) { | ||
| 3241 | 3248 | * Deletes a WI entry, with a user confirmation dialog |
| 3242 | 3249 | * @param {*[]} data - The data of the book |
| 3243 | 3250 | * @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 | |
| 3244 | 3254 | */ |
| 3245 | 3255 | export async function deleteWorldInfoEntry(data, uid, { silent = false } = {}) { |
| 3246 | 3256 | if (!data || !('entries' in data)) { |
| 3247 | 3257 | return; |
| 3248 | 3258 | } |
| 3249 | 3259 | |
| 3250 | 3260 | 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; | |
| 3252 | 3263 | } |
| 3253 | 3264 | |
| 3254 | 3265 | delete data.entries[uid]; |
| 3266 | + return true; | |
| 3255 | 3267 | } |
| 3256 | 3268 | |
| 3257 | 3269 | /** |