mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-12 09:26:33 +01:00
Fix/optimize bulk favorite
This commit is contained in:
parent
60909cef1f
commit
d36422e558
@ -69,30 +69,31 @@ class CharacterContextMenu {
|
|||||||
*/
|
*/
|
||||||
static favorite = async (characterId) => {
|
static favorite = async (characterId) => {
|
||||||
const character = CharacterContextMenu.#getCharacter(characterId);
|
const character = CharacterContextMenu.#getCharacter(characterId);
|
||||||
|
const newFavState = !character.data.extensions.fav;
|
||||||
|
|
||||||
// Only set fav for V2 spec
|
|
||||||
const data = {
|
const data = {
|
||||||
name: character.name,
|
name: character.name,
|
||||||
avatar: character.avatar,
|
avatar: character.avatar,
|
||||||
data: {
|
data: {
|
||||||
extensions: {
|
extensions: {
|
||||||
fav: !character.data.extensions.fav,
|
fav: newFavState,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
fav: newFavState,
|
||||||
};
|
};
|
||||||
|
|
||||||
return fetch('/api/characters/merge-attributes', {
|
const mergeResponse = await fetch('/api/characters/merge-attributes', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
}).then((response) => {
|
|
||||||
if (response.ok) {
|
|
||||||
const element = document.getElementById(`CharID${characterId}`);
|
|
||||||
element.classList.toggle('is_fav');
|
|
||||||
} else {
|
|
||||||
response.json().then(json => toastr.error('Character not saved. Error: ' + json.message + '. Field: ' + json.error));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!mergeResponse.ok) {
|
||||||
|
mergeResponse.json().then(json => toastr.error(`Character not saved. Error: ${json.message}. Field: ${json.error}`));
|
||||||
|
}
|
||||||
|
|
||||||
|
const element = document.getElementById(`CharID${characterId}`);
|
||||||
|
element.classList.toggle('is_fav');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -484,7 +485,7 @@ class BulkEditOverlay {
|
|||||||
this.container.removeEventListener('mouseup', cancelHold);
|
this.container.removeEventListener('mouseup', cancelHold);
|
||||||
this.container.removeEventListener('touchend', cancelHold);
|
this.container.removeEventListener('touchend', cancelHold);
|
||||||
},
|
},
|
||||||
BulkEditOverlay.longPressDelay);
|
BulkEditOverlay.longPressDelay);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleLongPressEnd = (event) => {
|
handleLongPressEnd = (event) => {
|
||||||
@ -529,7 +530,7 @@ class BulkEditOverlay {
|
|||||||
|
|
||||||
#getEnabledElements = () => [...this.container.getElementsByClassName(BulkEditOverlay.characterClass)];
|
#getEnabledElements = () => [...this.container.getElementsByClassName(BulkEditOverlay.characterClass)];
|
||||||
|
|
||||||
#getDisabledElements = () =>[...this.container.getElementsByClassName(BulkEditOverlay.groupClass), ...this.container.getElementsByClassName(BulkEditOverlay.bogusFolderClass)];
|
#getDisabledElements = () => [...this.container.getElementsByClassName(BulkEditOverlay.groupClass), ...this.container.getElementsByClassName(BulkEditOverlay.bogusFolderClass)];
|
||||||
|
|
||||||
toggleCharacterSelected = event => {
|
toggleCharacterSelected = event => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
@ -572,12 +573,20 @@ class BulkEditOverlay {
|
|||||||
/**
|
/**
|
||||||
* Concurrently handle character favorite requests.
|
* Concurrently handle character favorite requests.
|
||||||
*
|
*
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
handleContextMenuFavorite = () => Promise.all(this.selectedCharacters.map(async characterId => CharacterContextMenu.favorite(characterId)))
|
handleContextMenuFavorite = async () => {
|
||||||
.then(() => getCharacters())
|
const promises = [];
|
||||||
.then(() => favsToHotswap())
|
|
||||||
.then(() => this.browseState());
|
for (const characterId of this.selectedCharacters) {
|
||||||
|
promises.push(CharacterContextMenu.favorite(characterId));
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.allSettled(promises);
|
||||||
|
await getCharacters();
|
||||||
|
await favsToHotswap();
|
||||||
|
this.browseState();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Concurrently handle character duplicate requests.
|
* Concurrently handle character duplicate requests.
|
||||||
|
Loading…
Reference in New Issue
Block a user