Confirm custom PM prompt deletion

This commit is contained in:
Cohee
2024-09-23 22:44:49 +03:00
parent beeec51f93
commit a408328fc6

View File

@ -1,12 +1,13 @@
'use strict'; 'use strict';
import { callPopup, event_types, eventSource, is_send_press, main_api, substituteParams } from '../script.js'; import { event_types, eventSource, is_send_press, main_api, substituteParams } from '../script.js';
import { is_group_generating } from './group-chats.js'; import { is_group_generating } from './group-chats.js';
import { Message, TokenHandler } from './openai.js'; import { Message, TokenHandler } from './openai.js';
import { power_user } from './power-user.js'; import { power_user } from './power-user.js';
import { debounce, waitUntilCondition, escapeHtml } from './utils.js'; import { debounce, waitUntilCondition, escapeHtml } from './utils.js';
import { debounce_timeout } from './constants.js'; import { debounce_timeout } from './constants.js';
import { renderTemplateAsync } from './templates.js'; import { renderTemplateAsync } from './templates.js';
import { Popup } from './popup.js';
function debouncePromise(func, delay) { function debouncePromise(func, delay) {
let timeoutId; let timeoutId;
@ -453,7 +454,9 @@ class PromptManager {
}; };
// Delete selected prompt from list form and close edit form // Delete selected prompt from list form and close edit form
this.handleDeletePrompt = (event) => { this.handleDeletePrompt = async (event) => {
Popup.show.confirm('Are you sure you want to delete this prompt?', null).then((userChoice) => {
if (!userChoice) return;
const promptID = document.getElementById(this.configuration.prefix + 'prompt_manager_footer_append_prompt').value; const promptID = document.getElementById(this.configuration.prefix + 'prompt_manager_footer_append_prompt').value;
const prompt = this.getPromptById(promptID); const prompt = this.getPromptById(promptID);
@ -468,6 +471,7 @@ class PromptManager {
this.render(); this.render();
this.saveServiceSettings(); this.saveServiceSettings();
} }
});
}; };
// Create new prompt, then save it to settings and close form. // Create new prompt, then save it to settings and close form.
@ -527,9 +531,9 @@ class PromptManager {
// Import prompts for the selected character // Import prompts for the selected character
this.handleImport = () => { this.handleImport = () => {
callPopup('Existing prompts with the same ID will be overridden. Do you want to proceed?', 'confirm') Popup.show.confirm('Existing prompts with the same ID will be overridden. Do you want to proceed?', null)
.then(userChoice => { .then(userChoice => {
if (false === userChoice) return; if (!userChoice) return;
const fileOpener = document.createElement('input'); const fileOpener = document.createElement('input');
fileOpener.type = 'file'; fileOpener.type = 'file';
@ -563,9 +567,9 @@ class PromptManager {
// Restore default state of a characters prompt order // Restore default state of a characters prompt order
this.handleCharacterReset = () => { this.handleCharacterReset = () => {
callPopup('This will reset the prompt order for this character. You will not lose any prompts.', 'confirm') Popup.show.confirm('This will reset the prompt order for this character. You will not lose any prompts.', null)
.then(userChoice => { .then(userChoice => {
if (false === userChoice) return; if (!userChoice) return;
this.removePromptOrderForCharacter(this.activeCharacter); this.removePromptOrderForCharacter(this.activeCharacter);
this.addPromptOrderForCharacter(this.activeCharacter, promptManagerDefaultPromptOrder); this.addPromptOrderForCharacter(this.activeCharacter, promptManagerDefaultPromptOrder);