Add rename personas functionality
| @@ -696,6 +696,27 @@ async function updatePersonaNameIfExists(avatarId, newName) { | |||
| 696 | saveSettingsDebounced(); | 696 | saveSettingsDebounced(); |
| 697 | } | 697 | } |
| 698 | 698 | ||
| 699 | async function renamePersona(avatarId) { | ||
| 700 | const currentName = power_user.personas[avatarId]; | ||
| 701 | const newName = await Popup.show.input(t`Rename Persona`, t`Enter a new name for this persona:`, currentName); | ||
| 702 | if (!newName || newName === currentName) { | ||
| 703 | console.debug('User cancelled renaming persona or name is unchanged'); | ||
| 704 | return; | ||
| 705 | } | ||
| 706 | |||
| 707 | power_user.personas[avatarId] = newName; | ||
| 708 | console.log(`Renamed persona ${avatarId} to ${newName}`); | ||
| 709 | |||
| 710 | if (avatarId === user_avatar) { | ||
| 711 | setUserName(newName); | ||
| 712 | } | ||
| 713 | |||
| 714 | saveSettingsDebounced(); | ||
| 715 | await getUserAvatars(true, avatarId); | ||
| 716 | updatePersonaUIStates(); | ||
| 717 | setPersonaDescription(); | ||
| 718 | } | ||
| 719 | |||
| 699 | async function bindUserNameToPersona() { | 720 | async function bindUserNameToPersona() { |
| 700 | const avatarId = user_avatar; | 721 | const avatarId = user_avatar; |
| 701 | 722 | ||
| @@ -1164,18 +1185,6 @@ function getOrCreatePersonaDescriptor() { | |||
| 1164 | return object; | 1185 | return object; |
| 1165 | } | 1186 | } |
| 1166 | 1187 | ||
| 1167 | |||
| 1168 | |||
| 1169 | async function toggleDefaultPersonaClicked(e) { | ||
| 1170 | e?.stopPropagation(); | ||
| 1171 | const avatarId = $(e.currentTarget).closest('.avatar-container').find('.avatar').attr('data-avatar-id'); | ||
| 1172 | if (avatarId) { | ||
| 1173 | await toggleDefaultPersona(avatarId); | ||
| 1174 | } else { | ||
| 1175 | console.warn('No avatar id found'); | ||
| 1176 | } | ||
| 1177 | } | ||
| 1178 | |||
| 1179 | /** | 1188 | /** |
| 1180 | * Sets a persona as the default one to be used for all new chats and unlocked existing chats | 1189 | * Sets a persona as the default one to be used for all new chats and unlocked existing chats |
| 1181 | * @param {string} avatarId The avatar id of the persona to set as the default | 1190 | * @param {string} avatarId The avatar id of the persona to set as the default |
| @@ -1600,7 +1609,6 @@ async function duplicatePersona(avatarId) { | |||
| 1600 | } | 1609 | } |
| 1601 | 1610 | ||
| 1602 | export function initPersonas() { | 1611 | export function initPersonas() { |
| 1603 | $(document).on('click', '.set_default_persona', toggleDefaultPersonaClicked); | ||
| 1604 | $('#persona_delete_button').on('click', deleteUserAvatar); | 1612 | $('#persona_delete_button').on('click', deleteUserAvatar); |
| 1605 | $('#lock_persona_default').on('click', () => togglePersonaLock('default')); | 1613 | $('#lock_persona_default').on('click', () => togglePersonaLock('default')); |
| 1606 | $('#lock_user_name').on('click', () => togglePersonaLock('chat')); | 1614 | $('#lock_user_name').on('click', () => togglePersonaLock('chat')); |
| @@ -1647,14 +1655,7 @@ export function initPersonas() { | |||
| 1647 | retriggerFirstMessageOnEmptyChat(); | 1655 | retriggerFirstMessageOnEmptyChat(); |
| 1648 | }); | 1656 | }); |
| 1649 | 1657 | ||
| 1650 | $('#persona_rename_button').click(async function () { | 1658 | $('#persona_rename_button').on('click', () => renamePersona(user_avatar)); |
| 1651 | const userName = String($('#your_name').val()).trim(); | ||
| 1652 | setUserName(userName); | ||
| 1653 | await updatePersonaNameIfExists(user_avatar, userName); | ||
| 1654 | retriggerFirstMessageOnEmptyChat(); | ||
| 1655 | // TODO: Do both binding and/or rename? | ||
| 1656 | //bindUserNameToPersona(); | ||
| 1657 | }); | ||
| 1658 | 1659 | ||
| 1659 | $(document).on('click', '#user_avatar_block .avatar_upload', function () { | 1660 | $(document).on('click', '#user_avatar_block .avatar_upload', function () { |
| 1660 | $('#avatar_upload_overwrite').val(''); | 1661 | $('#avatar_upload_overwrite').val(''); |
| @@ -3887,10 +3887,6 @@ input[type='checkbox'].del_checkbox { | |||
| 3887 | outline: var(--avatar-base-border-radius) solid var(--golden); | 3887 | outline: var(--avatar-base-border-radius) solid var(--golden); |
| 3888 | } | 3888 | } |
| 3889 | 3889 | ||
| 3890 | .avatar-container.default_persona .set_default_persona { | ||
| 3891 | color: var(--golden); | ||
| 3892 | } | ||
| 3893 | |||
| 3894 | .avatar-container .avatar_state .fa-lock { | 3890 | .avatar-container .avatar_state .fa-lock { |
| 3895 | color: var(--active); | 3891 | color: var(--active); |
| 3896 | } | 3892 | } |