mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-11 17:07:07 +01:00
Persist current page on persona actions
This commit is contained in:
parent
be62903adb
commit
fa73c523f0
@ -821,7 +821,7 @@ async function firstLoadInit() {
|
||||
await readSecretState();
|
||||
await getClientVersion();
|
||||
await getSettings();
|
||||
await getUserAvatars();
|
||||
await getUserAvatars(true, user_avatar);
|
||||
await getCharacters();
|
||||
await getBackgrounds();
|
||||
await initTokenizers();
|
||||
@ -5400,9 +5400,10 @@ function changeMainAPI() {
|
||||
/**
|
||||
* Gets a list of user avatars.
|
||||
* @param {boolean} doRender Whether to render the list
|
||||
* @param {string} openPageAt Item to be opened at
|
||||
* @returns {Promise<string[]>} List of avatar file names
|
||||
*/
|
||||
export async function getUserAvatars(doRender = true) {
|
||||
export async function getUserAvatars(doRender = true, openPageAt = '') {
|
||||
const response = await fetch('/getuseravatars', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
@ -5418,10 +5419,11 @@ export async function getUserAvatars(doRender = true) {
|
||||
|
||||
const storageKey = 'Personas_PerPage';
|
||||
const listId = '#user_avatar_block';
|
||||
const perPage = Number(localStorage.getItem(storageKey)) || 5;
|
||||
|
||||
$('#persona_pagination_container').pagination({
|
||||
dataSource: entities,
|
||||
pageSize: Number(localStorage.getItem(storageKey)) || 5,
|
||||
pageSize: perPage,
|
||||
sizeChangerOptions: [5, 10, 25, 50, 100, 250, 500, 1000],
|
||||
pageRange: 1,
|
||||
pageNumber: savePersonasPage || 1,
|
||||
@ -5450,6 +5452,15 @@ export async function getUserAvatars(doRender = true) {
|
||||
},
|
||||
});
|
||||
|
||||
if (openPageAt) {
|
||||
const avatarIndex = entities.indexOf(openPageAt);
|
||||
const page = Math.floor(avatarIndex / perPage) + 1;
|
||||
|
||||
if (avatarIndex !== -1 && page > 1) {
|
||||
$('#persona_pagination_container').pagination('go', page);
|
||||
}
|
||||
}
|
||||
|
||||
return allEntities;
|
||||
}
|
||||
}
|
||||
@ -5563,7 +5574,7 @@ async function uploadUserAvatar(e) {
|
||||
}
|
||||
|
||||
crop_data = undefined;
|
||||
await getUserAvatars();
|
||||
await getUserAvatars(true, name || data.path);
|
||||
},
|
||||
error: (jqXHR, exception) => { },
|
||||
});
|
||||
|
@ -47,7 +47,7 @@ async function uploadUserAvatar(url, name) {
|
||||
contentType: false,
|
||||
processData: false,
|
||||
success: async function () {
|
||||
await getUserAvatars();
|
||||
await getUserAvatars(true, name);
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -157,7 +157,7 @@ export async function convertCharacterToPersona(characterId = null) {
|
||||
toastr.success(`You can now select ${name} as a persona in the Persona Management menu.`, 'Persona Created');
|
||||
|
||||
// Refresh the persona selector
|
||||
await getUserAvatars();
|
||||
await getUserAvatars(true, overwriteName);
|
||||
// Reload the persona description
|
||||
setPersonaDescription();
|
||||
}
|
||||
@ -202,7 +202,7 @@ export function autoSelectPersona(name) {
|
||||
export async function updatePersonaNameIfExists(avatarId, newName) {
|
||||
if (avatarId in power_user.personas) {
|
||||
power_user.personas[avatarId] = newName;
|
||||
await getUserAvatars();
|
||||
await getUserAvatars(true, avatarId);
|
||||
saveSettingsDebounced();
|
||||
console.log(`Updated persona name for ${avatarId} to ${newName}`);
|
||||
} else {
|
||||
@ -256,7 +256,7 @@ async function bindUserNameToPersona(e) {
|
||||
}
|
||||
|
||||
saveSettingsDebounced();
|
||||
await getUserAvatars();
|
||||
await getUserAvatars(true, avatarId);
|
||||
setPersonaDescription();
|
||||
}
|
||||
|
||||
@ -479,7 +479,7 @@ async function setDefaultPersona(e) {
|
||||
}
|
||||
|
||||
saveSettingsDebounced();
|
||||
await getUserAvatars();
|
||||
await getUserAvatars(true, avatarId);
|
||||
}
|
||||
|
||||
function updateUserLockIcon() {
|
||||
|
Loading…
Reference in New Issue
Block a user