Update delete WI entry to new popup

This commit is contained in:
Wolfsblvt 2024-08-02 20:51:12 +02:00
parent 3897b8c082
commit c0039111dd
1 changed files with 17 additions and 5 deletions

View File

@ -2115,7 +2115,13 @@ export function setWIOriginalDataValue(data, uid, key, value) {
} }
} }
function deleteWIOriginalDataValue(data, uid) { /**
* Deletes the original data entry corresponding to the given uid from the provided data object
*
* @param {object} data - The data object containing the original data entries
* @param {string} uid - The unique identifier of the data entry to be deleted
*/
export function deleteWIOriginalDataValue(data, uid) {
if (data.originalData && Array.isArray(data.originalData.entries)) { if (data.originalData && Array.isArray(data.originalData.entries)) {
const originalIndex = data.originalData.entries.findIndex(x => x.uid === uid); const originalIndex = data.originalData.entries.findIndex(x => x.uid === uid);
@ -3003,7 +3009,8 @@ function getWorldEntry(name, data, entry) {
deleteButton.data('uid', entry.uid); deleteButton.data('uid', entry.uid);
deleteButton.on('click', async function () { deleteButton.on('click', async function () {
const uid = $(this).data('uid'); const uid = $(this).data('uid');
deleteWorldInfoEntry(data, uid); const deleted = await deleteWorldInfoEntry(data, uid);
if (!deleted) return;
deleteWIOriginalDataValue(data, uid); deleteWIOriginalDataValue(data, uid);
await saveWorldInfo(name, data); await saveWorldInfo(name, data);
updateEditor(navigation_option.previous); updateEditor(navigation_option.previous);
@ -3241,17 +3248,22 @@ export function duplicateWorldInfoEntry(data, uid) {
* Deletes a WI entry, with a user confirmation dialog * Deletes a WI entry, with a user confirmation dialog
* @param {*[]} data - The data of the book * @param {*[]} data - The data of the book
* @param {number} uid - The uid of the entry to copy in this book * @param {number} uid - The uid of the entry to copy in this book
* @param {object} [options={}] - Optional arguments
* @param {boolean} [options.silent=false] - Whether to prompt the user for deletion or just do it
* @returns {Promise<boolean>} Whether the entry deletion was successful
*/ */
export function deleteWorldInfoEntry(data, uid) { export async function deleteWorldInfoEntry(data, uid, { silent = false } = {}) {
if (!data || !('entries' in data)) { if (!data || !('entries' in data)) {
return; return;
} }
if (!confirm(`Delete the entry with UID: ${uid}? This action is irreversible!`)) { const confirmation = silent || await Popup.show.confirm(`Delete the entry with UID: ${uid}?`, 'This action is irreversible!');
throw new Error('User cancelled deletion'); if (!confirmation) {
return false;
} }
delete data.entries[uid]; delete data.entries[uid];
return true;
} }
/** /**