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