implemented emit events for itemized-prompts.js (#5461) * implemented emit events for itemized-prompts.js * removed redundant ITEMIZED_PROMPTS_DELETED_ALL event and updated emit logic accordingly --------- Co-authored-by: Peter Vanusanik <pvan@bach.cz>

277285d30cb096cfc93c92b27f3e0afa1003cba6

Enerccio <admin@en-circle.com>

Signed
2 files changed, +8 -0Ignore whitespace
public/scripts/events.js+3 -0
@@ -105,6 +105,9 @@ export const event_types = {
105105 TTS_JOB_STARTED: 'tts_job_started',
106106 TTS_AUDIO_READY: 'tts_audio_ready',
107107 TTS_JOB_COMPLETE: 'tts_job_complete',
108+ ITEMIZED_PROMPTS_LOADED: 'itemized_prompts_loaded',
109+ ITEMIZED_PROMPTS_SAVED: 'itemized_prompts_saved',
110+ ITEMIZED_PROMPTS_DELETED: 'itemized_prompts_deleted',
108111};
109112
110113export const eventSource = new EventEmitter([event_types.APP_READY, event_types.APP_INITIALIZED]);
public/scripts/itemized-prompts.js+5 -0
@@ -31,6 +31,8 @@ export async function loadItemizedPrompts(chatId) {
3131 if (!itemizedPrompts) {
3232 itemizedPrompts = [];
3333 }
34+
35+ await eventSource.emit(event_types.ITEMIZED_PROMPTS_LOADED, { chatId: chatId });
3436 } catch {
3537 console.log('Error loading itemized prompts for chat', chatId);
3638 itemizedPrompts = [];
@@ -48,6 +50,7 @@ export async function saveItemizedPrompts(chatId) {
4850 }
4951
5052 await promptStorage.setItem(chatId, itemizedPrompts);
53+ await eventSource.emit(event_types.ITEMIZED_PROMPTS_SAVED, { chatId: chatId });
5154 } catch {
5255 console.log('Error saving itemized prompts for chat', chatId);
5356 }
@@ -84,6 +87,7 @@ export async function deleteItemizedPrompts(chatId) {
8487 }
8588
8689 await promptStorage.removeItem(chatId);
90+ await eventSource.emit(event_types.ITEMIZED_PROMPTS_DELETED, { chatId: chatId, all: false });
8791 } catch {
8892 console.log('Error deleting itemized prompts for chat', chatId);
8993 }
@@ -96,6 +100,7 @@ export async function clearItemizedPrompts() {
96100 try {
97101 await promptStorage.clear();
98102 itemizedPrompts = [];
103+ await eventSource.emit(event_types.ITEMIZED_PROMPTS_DELETED, { all: true });
99104 } catch {
100105 console.log('Error clearing itemized prompts');
101106 }