mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-12 18:10:39 +01:00
Add dupe functionality to context menu
This commit is contained in:
parent
ec9d43d26d
commit
a3685504ba
@ -1,6 +1,13 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import {characters, event_types, eventSource, getOneCharacter} from "../script.js";
|
import {
|
||||||
|
characters,
|
||||||
|
event_types,
|
||||||
|
eventSource,
|
||||||
|
getCharacters,
|
||||||
|
getOneCharacter,
|
||||||
|
getRequestHeaders
|
||||||
|
} from "../script.js";
|
||||||
import {favsToHotswap} from "./RossAscends-mods.js";
|
import {favsToHotswap} from "./RossAscends-mods.js";
|
||||||
|
|
||||||
const toggleFavoriteHighlight = (characterId) => {
|
const toggleFavoriteHighlight = (characterId) => {
|
||||||
@ -22,7 +29,21 @@ class CharacterGroupOverlayState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CharacterContextMenu {
|
class CharacterContextMenu {
|
||||||
|
/**
|
||||||
|
* Duplicate a character
|
||||||
|
*
|
||||||
|
* @param characterId
|
||||||
|
* @returns {Promise<Response>}
|
||||||
|
*/
|
||||||
|
static duplicate = async (characterId) => {
|
||||||
|
const character = CharacterContextMenu.getCharacter(characterId);
|
||||||
|
|
||||||
|
return fetch('/dupecharacter', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: getRequestHeaders(),
|
||||||
|
body: JSON.stringify({ avatar_url: character.avatar }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static favorite = (characterId) => {
|
static favorite = (characterId) => {
|
||||||
const character = CharacterContextMenu.getCharacter(characterId);
|
const character = CharacterContextMenu.getCharacter(characterId);
|
||||||
@ -73,7 +94,8 @@ class CharacterContextMenu {
|
|||||||
|
|
||||||
constructor(characterGroupOverlay) {
|
constructor(characterGroupOverlay) {
|
||||||
const contextMenuItems = [
|
const contextMenuItems = [
|
||||||
{id: 'character_context_menu_favorite', callback: characterGroupOverlay.handleContextMenuFavorite}
|
{id: 'character_context_menu_favorite', callback: characterGroupOverlay.handleContextMenuFavorite},
|
||||||
|
{id: 'character_context_menu_duplicate', callback: characterGroupOverlay.handleContextMenuDuplicate}
|
||||||
];
|
];
|
||||||
|
|
||||||
contextMenuItems.forEach(contextMenuItem => document.getElementById(contextMenuItem.id).addEventListener('click', contextMenuItem.callback))
|
contextMenuItems.forEach(contextMenuItem => document.getElementById(contextMenuItem.id).addEventListener('click', contextMenuItem.callback))
|
||||||
@ -260,6 +282,11 @@ class CharacterGroupOverlay {
|
|||||||
|
|
||||||
handleContextMenuFavorite = () => this.selectedCharacters.forEach(characterId => CharacterContextMenu.favorite(characterId));
|
handleContextMenuFavorite = () => this.selectedCharacters.forEach(characterId => CharacterContextMenu.favorite(characterId));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aggregate duplicate promises for selected characters
|
||||||
|
*/
|
||||||
|
handleContextMenuDuplicate = () => Promise.all(this.selectedCharacters.map(async characterId => CharacterContextMenu.duplicate(characterId))).then(() => getCharacters())
|
||||||
|
|
||||||
addStateChangeCallback = callback => this.stateChangeCallbacks.push(callback);
|
addStateChangeCallback = callback => this.stateChangeCallbacks.push(callback);
|
||||||
|
|
||||||
selectCharacter = characterId => this.selectedCharacters.push(String(characterId));
|
selectCharacter = characterId => this.selectedCharacters.push(String(characterId));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user