From 31d0aa114d91ed1927ca7249806182b888b86ba1 Mon Sep 17 00:00:00 2001 From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:00:33 -0500 Subject: [PATCH] AI Clear Button (#1274) Adds a button and Cmd:l keybinding to clear the ai message history in the current block --- frontend/app/view/waveai/waveai.tsx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/frontend/app/view/waveai/waveai.tsx b/frontend/app/view/waveai/waveai.tsx index 338b9077e..92e1cc9b6 100644 --- a/frontend/app/view/waveai/waveai.tsx +++ b/frontend/app/view/waveai/waveai.tsx @@ -252,6 +252,14 @@ export class WaveAiModel implements ViewModel { }); return viewTextChildren; }); + this.endIconButtons = atom((get) => { + let clearButton: IconButtonDecl = { + elemtype: "iconbutton", + icon: "delete-left", + click: this.clearMessages.bind(this), + }; + return [clearButton]; + }); } dispose() { @@ -387,6 +395,19 @@ export class WaveAiModel implements ViewModel { sendMessage: this.sendMessage.bind(this), }; } + + async clearMessages() { + await BlockService.SaveWaveAiData(this.blockId, []); + globalStore.set(this.messagesAtom, []); + } + + keyDownHandler(waveEvent: WaveKeyboardEvent): boolean { + if (checkKeyPressed(waveEvent, "Cmd:l")) { + this.clearMessages(); + return true; + } + return false; + } } function makeWaveAiViewModel(blockId): WaveAiModel {