Update popups to new
| @@ -1,5 +1,4 @@ | |||
| 1 | import { | 1 | import { |
| 2 | callPopup, | ||
| 3 | characters, | 2 | characters, |
| 4 | chat, | 3 | chat, |
| 5 | chat_metadata, | 4 | chat_metadata, |
| @@ -22,7 +21,7 @@ import { PAGINATION_TEMPLATE, debounce, delay, download, ensureImageFormatSuppor | |||
| 22 | import { debounce_timeout } from './constants.js'; | 21 | import { debounce_timeout } from './constants.js'; |
| 23 | import { FILTER_TYPES, FilterHelper } from './filters.js'; | 22 | import { FILTER_TYPES, FilterHelper } from './filters.js'; |
| 24 | import { selected_group } from './group-chats.js'; | 23 | import { selected_group } from './group-chats.js'; |
| 25 | import { POPUP_TYPE, Popup } from './popup.js'; | 24 | import { POPUP_RESULT, POPUP_TYPE, Popup } from './popup.js'; |
| 26 | 25 | ||
| 27 | let savePersonasPage = 0; | 26 | let savePersonasPage = 0; |
| 28 | const GRID_STORAGE_KEY = 'Personas_GridView'; | 27 | const GRID_STORAGE_KEY = 'Personas_GridView'; |
| @@ -332,15 +331,14 @@ async function changeUserAvatar(e) { | |||
| 332 | * @returns {Promise} Promise that resolves when the persona is set | 331 | * @returns {Promise} Promise that resolves when the persona is set |
| 333 | */ | 332 | */ |
| 334 | export async function createPersona(avatarId) { | 333 | export async function createPersona(avatarId) { |
| 335 | const personaName = await callPopup('<h3>Enter a name for this persona:</h3>Cancel if you\'re just uploading an avatar.', 'input', ''); | 334 | const personaName = await Popup.show.input('Enter a name for this persona:', 'Cancel if you\'re just uploading an avatar.', ''); |
| 336 | 335 | ||
| 337 | if (!personaName) { | 336 | if (!personaName) { |
| 338 | console.debug('User cancelled creating a persona'); | 337 | console.debug('User cancelled creating a persona'); |
| 339 | return; | 338 | return; |
| 340 | } | 339 | } |
| 341 | 340 | ||
| 342 | await delay(500); | 341 | const personaDescription = await Popup.show.input('Enter a description for this persona:', 'You can always add or change it later.', '', { rows: 4 }); |
| 343 | const personaDescription = await callPopup('<h3>Enter a description for this persona:</h3>You can always add or change it later.', 'input', '', { rows: 4 }); | ||
| 344 | 342 | ||
| 345 | initPersona(avatarId, personaName, personaDescription); | 343 | initPersona(avatarId, personaName, personaDescription); |
| 346 | if (power_user.persona_show_notifications) { | 344 | if (power_user.persona_show_notifications) { |
| @@ -349,7 +347,7 @@ export async function createPersona(avatarId) { | |||
| 349 | } | 347 | } |
| 350 | 348 | ||
| 351 | async function createDummyPersona() { | 349 | async function createDummyPersona() { |
| 352 | const personaName = await callPopup('<h3>Enter a name for this persona:</h3>', 'input', ''); | 350 | const personaName = await Popup.show.input('Enter a name for this persona:', null); |
| 353 | 351 | ||
| 354 | if (!personaName) { | 352 | if (!personaName) { |
| 355 | console.debug('User cancelled creating dummy persona'); | 353 | console.debug('User cancelled creating dummy persona'); |
| @@ -508,15 +506,20 @@ async function bindUserNameToPersona(e) { | |||
| 508 | return; | 506 | return; |
| 509 | } | 507 | } |
| 510 | 508 | ||
| 509 | let personaUnbind = false; | ||
| 511 | const existingPersona = power_user.personas[avatarId]; | 510 | const existingPersona = power_user.personas[avatarId]; |
| 512 | const personaName = await callPopup('<h3>Enter a name for this persona:</h3>(If empty name is provided, this will unbind the name from this avatar)', 'input', existingPersona || ''); | 511 | const personaName = await Popup.show.input( |
| 512 | 'Enter a name for this persona:', | ||
| 513 | '(If empty name is provided, this will unbind the name from this avatar)', | ||
| 514 | existingPersona || '', | ||
| 515 | { onClose: (p) => { personaUnbind = p.value === '' && p.result === POPUP_RESULT.AFFIRMATIVE; } }); | ||
| 513 | 516 | ||
| 514 | // If the user clicked cancel, don't do anything | 517 | // If the user clicked cancel, don't do anything |
| 515 | if (personaName === false) { | 518 | if (personaName === null && !personaUnbind) { |
| 516 | return; | 519 | return; |
| 517 | } | 520 | } |
| 518 | 521 | ||
| 519 | if (personaName.length > 0) { | 522 | if (personaName && personaName.length > 0) { |
| 520 | // If the user clicked ok and entered a name, bind the name to the persona | 523 | // If the user clicked ok and entered a name, bind the name to the persona |
| 521 | console.log(`Binding persona ${avatarId} to name ${personaName}`); | 524 | console.log(`Binding persona ${avatarId} to name ${personaName}`); |
| 522 | power_user.personas[avatarId] = personaName; | 525 | power_user.personas[avatarId] = personaName; |
| @@ -672,7 +675,7 @@ async function deleteUserAvatar(e) { | |||
| 672 | return; | 675 | return; |
| 673 | } | 676 | } |
| 674 | 677 | ||
| 675 | const confirm = await callPopup('<h3>Are you sure you want to delete this avatar?</h3>All information associated with its linked persona will be lost.', 'confirm'); | 678 | const confirm = await Popup.show.confirm('Are you sure you want to delete this avatar?', 'All information associated with its linked persona will be lost.'); |
| 676 | 679 | ||
| 677 | if (!confirm) { | 680 | if (!confirm) { |
| 678 | console.debug('User cancelled deleting avatar'); | 681 | console.debug('User cancelled deleting avatar'); |
| @@ -806,7 +809,7 @@ async function setDefaultPersona(e) { | |||
| 806 | const personaName = power_user.personas[avatarId]; | 809 | const personaName = power_user.personas[avatarId]; |
| 807 | 810 | ||
| 808 | if (avatarId === currentDefault) { | 811 | if (avatarId === currentDefault) { |
| 809 | const confirm = await callPopup('Are you sure you want to remove the default persona?', 'confirm'); | 812 | const confirm = await Popup.show.confirm('Are you sure you want to remove the default persona?', personaName); |
| 810 | 813 | ||
| 811 | if (!confirm) { | 814 | if (!confirm) { |
| 812 | console.debug('User cancelled removing default persona'); | 815 | console.debug('User cancelled removing default persona'); |
| @@ -819,8 +822,7 @@ async function setDefaultPersona(e) { | |||
| 819 | } | 822 | } |
| 820 | delete power_user.default_persona; | 823 | delete power_user.default_persona; |
| 821 | } else { | 824 | } else { |
| 822 | const confirm = await callPopup(`<h3>Are you sure you want to set "${personaName}" as the default persona?</h3> | 825 | const confirm = await Popup.show.confirm(`Are you sure you want to set "${personaName}" as the default persona?`, 'This name and avatar will be used for all new chats, as well as existing chats where the user persona is not locked.'); |
| 823 | This name and avatar will be used for all new chats, as well as existing chats where the user persona is not locked.`, 'confirm'); | ||
| 824 | 826 | ||
| 825 | if (!confirm) { | 827 | if (!confirm) { |
| 826 | console.debug('User cancelled setting default persona'); | 828 | console.debug('User cancelled setting default persona'); |
| @@ -978,7 +980,7 @@ async function onPersonasRestoreInput(e) { | |||
| 978 | } | 980 | } |
| 979 | 981 | ||
| 980 | async function syncUserNameToPersona() { | 982 | async function syncUserNameToPersona() { |
| 981 | const confirmation = await callPopup(`<h3>Are you sure?</h3>All user-sent messages in this chat will be attributed to ${name1}.`, 'confirm'); | 983 | const confirmation = await Popup.show.confirm('Are you sure?', `All user-sent messages in this chat will be attributed to ${name1}.`); |
| 982 | 984 | ||
| 983 | if (!confirmation) { | 985 | if (!confirmation) { |
| 984 | return; | 986 | return; |