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 = {
105 TTS_JOB_STARTED: 'tts_job_started',105 TTS_JOB_STARTED: 'tts_job_started',
106 TTS_AUDIO_READY: 'tts_audio_ready',106 TTS_AUDIO_READY: 'tts_audio_ready',
107 TTS_JOB_COMPLETE: 'tts_job_complete',107 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',
108};111};
109112
110export const eventSource = new EventEmitter([event_types.APP_READY, event_types.APP_INITIALIZED]);113export 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) {
31 if (!itemizedPrompts) {31 if (!itemizedPrompts) {
32 itemizedPrompts = [];32 itemizedPrompts = [];
33 }33 }
34
35 await eventSource.emit(event_types.ITEMIZED_PROMPTS_LOADED, { chatId: chatId });
34 } catch {36 } catch {
35 console.log('Error loading itemized prompts for chat', chatId);37 console.log('Error loading itemized prompts for chat', chatId);
36 itemizedPrompts = [];38 itemizedPrompts = [];
@@ -48,6 +50,7 @@ export async function saveItemizedPrompts(chatId) {
48 }50 }
4951
50 await promptStorage.setItem(chatId, itemizedPrompts);52 await promptStorage.setItem(chatId, itemizedPrompts);
53 await eventSource.emit(event_types.ITEMIZED_PROMPTS_SAVED, { chatId: chatId });
51 } catch {54 } catch {
52 console.log('Error saving itemized prompts for chat', chatId);55 console.log('Error saving itemized prompts for chat', chatId);
53 }56 }
@@ -84,6 +87,7 @@ export async function deleteItemizedPrompts(chatId) {
84 }87 }
8588
86 await promptStorage.removeItem(chatId);89 await promptStorage.removeItem(chatId);
90 await eventSource.emit(event_types.ITEMIZED_PROMPTS_DELETED, { chatId: chatId, all: false });
87 } catch {91 } catch {
88 console.log('Error deleting itemized prompts for chat', chatId);92 console.log('Error deleting itemized prompts for chat', chatId);
89 }93 }
@@ -96,6 +100,7 @@ export async function clearItemizedPrompts() {
96 try {100 try {
97 await promptStorage.clear();101 await promptStorage.clear();
98 itemizedPrompts = [];102 itemizedPrompts = [];
103 await eventSource.emit(event_types.ITEMIZED_PROMPTS_DELETED, { all: true });
99 } catch {104 } catch {
100 console.log('Error clearing itemized prompts');105 console.log('Error clearing itemized prompts');
101 }106 }