Allow users to delete their chats when deleting characters

This commit is contained in:
artisticMink
2023-10-26 18:53:27 +02:00
parent d401aa1a6f
commit 7972307b69

View File

@@ -1,15 +1,26 @@
"use strict"; "use strict";
import { import {
callPopup,
characters, deleteCharacter, characters, deleteCharacter,
event_types, event_types,
eventSource, eventSource,
getCharacters, getCharacters,
getOneCharacter,
getRequestHeaders, handleDeleteCharacter, this_chid getRequestHeaders, handleDeleteCharacter, this_chid
} from "../script.js"; } from "../script.js";
import {favsToHotswap} from "./RossAscends-mods.js"; import {favsToHotswap} from "./RossAscends-mods.js";
const popupMessage = {
deleteChat(characterCount) {
return `<h3>Delete ${characterCount} characters?</h3>
<b>THIS IS PERMANENT!<br><br>
<label for="del_char_checkbox" class="checkbox_label justifyCenter">
<input type="checkbox" id="del_char_checkbox" />
<span>Also delete the chat files</span>
</label><br></b>`;
}
}
const toggleFavoriteHighlight = (characterId) => { const toggleFavoriteHighlight = (characterId) => {
const element = document.getElementById(`CharID${characterId}`); const element = document.getElementById(`CharID${characterId}`);
element.classList.toggle('is_fav'); element.classList.toggle('is_fav');
@@ -317,9 +328,16 @@ class CharacterGroupOverlay {
.then(() => getCharacters()) .then(() => getCharacters())
.then(() => this.browseState()) .then(() => this.browseState())
handleContextMenuDelete = () => Promise.all(this.selectedCharacters.map(async characterId => CharacterContextMenu.delete(characterId))) handleContextMenuDelete = () => {
callPopup(
popupMessage.deleteChat(this.selectedCharacters.length),
null
).then(deleteChats =>
Promise.all(this.selectedCharacters.map(async characterId => CharacterContextMenu.delete(characterId, deleteChats)))
.then(() => getCharacters()) .then(() => getCharacters())
.then(() => this.browseState()) .then(() => this.browseState())
);
}
addStateChangeCallback = callback => this.stateChangeCallbacks.push(callback); addStateChangeCallback = callback => this.stateChangeCallbacks.push(callback);