mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Use EventEmitter instead of native event handling
This commit is contained in:
@@ -7522,6 +7522,7 @@ $(document).ready(function () {
|
||||
if (popup_type == "del_ch") {
|
||||
const deleteChats = !!$("#del_char_checkbox").prop("checked");
|
||||
await handleDeleteCharacter(popup_type, this_chid, deleteChats);
|
||||
eventSource.emit('characterDeleted', {id: this_chid, character: characters[this_chid]});
|
||||
}
|
||||
if (popup_type == "alternate_greeting" && menu_type !== "create") {
|
||||
createOrEditCharacter();
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import {countTokens} from "./openai.js";
|
||||
import {DraggablePromptListModule as DraggableList} from "./DraggableList.js";
|
||||
import {substituteParams} from "../script.js";
|
||||
import {eventSource, substituteParams} from "../script.js";
|
||||
|
||||
// Thrown by ChatCompletion when a requested prompt couldn't be found.
|
||||
class IdentifierNotFoundError extends Error {
|
||||
@@ -227,19 +227,19 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
}
|
||||
|
||||
// Re-render when the character changes.
|
||||
document.addEventListener('characterSelected', (event) => {
|
||||
eventSource.on('characterSelected', (event) => {
|
||||
this.handleCharacterSelected(event)
|
||||
this.saveServiceSettings().then(() => this.render());
|
||||
});
|
||||
|
||||
// Re-render when the group changes.
|
||||
document.addEventListener('groupSelected', (event) => {
|
||||
eventSource.on('groupSelected', (event) => {
|
||||
this.handleGroupSelected(event)
|
||||
this.saveServiceSettings().then(() => this.render());
|
||||
});
|
||||
|
||||
// Sanitize settings after character has been deleted.
|
||||
document.addEventListener('characterDeleted', (event) => {
|
||||
eventSource.on('characterDeleted', (event) => {
|
||||
this.handleCharacterDeleted(event)
|
||||
this.saveServiceSettings().then(() => this.render());
|
||||
});
|
||||
|
@@ -13,6 +13,7 @@ import {
|
||||
menu_type,
|
||||
max_context,
|
||||
saveSettingsDebounced,
|
||||
eventSource,
|
||||
active_group,
|
||||
active_character,
|
||||
setActiveGroup,
|
||||
@@ -924,6 +925,16 @@ $("document").ready(function () {
|
||||
$(document).on("click", ".character_select", function () {
|
||||
setActiveCharacter($(this).find('.avatar').attr('title'));
|
||||
setActiveGroup(null);
|
||||
|
||||
const chid = $(this).attr('chid');
|
||||
eventSource.emit(
|
||||
'characterSelected',
|
||||
{detail: {id: chid, character: characters[chid]}})
|
||||
.then(r => {
|
||||
SaveLocal('ActiveChar', chid);
|
||||
SaveLocal('ActiveGroup', null);
|
||||
});
|
||||
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
|
@@ -1167,7 +1167,7 @@ function select_group_chats(groupId, skipAnimation) {
|
||||
await eventSource.emit(event_types.GROUP_UPDATED);
|
||||
});
|
||||
|
||||
document.dispatchEvent(new CustomEvent('groupSelected', { detail: {id: groupId, group: group}}));
|
||||
eventSource.emit('groupSelected', {detail: {id: groupId, group: group}});
|
||||
}
|
||||
|
||||
function updateFavButtonState(state) {
|
||||
|
Reference in New Issue
Block a user