Navigate to current persona on switching chats
| @@ -68,6 +68,8 @@ export let user_avatar = ''; | |||
| 68 | /** @type {FilterHelper} Filter helper for the persona list */ | 68 | /** @type {FilterHelper} Filter helper for the persona list */ |
| 69 | export const personasFilter = new FilterHelper(debounce(getUserAvatars, debounce_timeout.quick)); | 69 | export const personasFilter = new FilterHelper(debounce(getUserAvatars, debounce_timeout.quick)); |
| 70 | 70 | ||
| 71 | /** @type {function(string): void} */ | ||
| 72 | let navigateToAvatar = () => { }; | ||
| 71 | 73 | ||
| 72 | /** | 74 | /** |
| 73 | * Checks if the Persona Management panel is currently open | 75 | * Checks if the Persona Management panel is currently open |
| @@ -276,14 +278,16 @@ export async function getUserAvatars(doRender = true, openPageAt = '') { | |||
| 276 | }, | 278 | }, |
| 277 | }); | 279 | }); |
| 278 | 280 | ||
| 279 | if (openPageAt) { | 281 | navigateToAvatar = (avatarId) => { |
| 280 | const avatarIndex = entities.indexOf(openPageAt); | 282 | const avatarIndex = entities.indexOf(avatarId); |
| 281 | const page = Math.floor(avatarIndex / perPage) + 1; | 283 | const page = Math.floor(avatarIndex / perPage) + 1; |
| 282 | 284 | ||
| 283 | if (avatarIndex !== -1) { | 285 | if (avatarIndex !== -1) { |
| 284 | $('#persona_pagination_container').pagination('go', page); | 286 | $('#persona_pagination_container').pagination('go', page); |
| 285 | } | 287 | } |
| 286 | } | 288 | }; |
| 289 | |||
| 290 | openPageAt && navigateToAvatar(openPageAt); | ||
| 287 | 291 | ||
| 288 | return allEntities; | 292 | return allEntities; |
| 289 | } | 293 | } |
| @@ -1255,9 +1259,15 @@ function getPersonaStates(avatarId) { | |||
| 1255 | * and character lock, as well as updating icons and labels in the persona management panel to reflect | 1259 | * and character lock, as well as updating icons and labels in the persona management panel to reflect |
| 1256 | * the current state of the user's persona. | 1260 | * the current state of the user's persona. |
| 1257 | * Additionally, it manages the display of temporary persona lock information. | 1261 | * Additionally, it manages the display of temporary persona lock information. |
| 1262 | * @param {Object} [options={}] - Optional settings | ||
| 1263 | * @param {boolean} [options.navigateToCurrent=false] - Whether to navigate to the current persona in the persona list | ||
| 1258 | */ | 1264 | */ |
| 1259 | 1265 | ||
| 1260 | function updatePersonaUIStates() { | 1266 | function updatePersonaUIStates({ navigateToCurrent = false } = {}) { |
| 1267 | if (navigateToCurrent) { | ||
| 1268 | navigateToAvatar(user_avatar); | ||
| 1269 | } | ||
| 1270 | |||
| 1261 | // Update the persona list | 1271 | // Update the persona list |
| 1262 | $('#user_avatar_block .avatar-container').each(function () { | 1272 | $('#user_avatar_block .avatar-container').each(function () { |
| 1263 | const avatarId = $(this).attr('data-avatar-id'); | 1273 | const avatarId = $(this).attr('data-avatar-id'); |
| @@ -1450,7 +1460,7 @@ async function loadPersonaForCurrentChat({ doRender = false } = {}) { | |||
| 1450 | } | 1460 | } |
| 1451 | } | 1461 | } |
| 1452 | 1462 | ||
| 1453 | updatePersonaUIStates(); | 1463 | updatePersonaUIStates({ navigateToCurrent: true }); |
| 1454 | 1464 | ||
| 1455 | return !!chatPersona; | 1465 | return !!chatPersona; |
| 1456 | } | 1466 | } |