From a96b7e5b4d9973a0d02d8d64f0b1f49b89f9decb Mon Sep 17 00:00:00 2001 From: Nicolas Brichet Date: Thu, 6 Feb 2025 17:41:39 +0100 Subject: [PATCH] Use await to select files Co-authored-by: David L. Qiu <44106031+dlqqq@users.noreply.github.com> --- .../src/components/input/attach-button.tsx | 29 +++++++++---------- packages/jupyter-chat/src/model.ts | 4 +-- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/packages/jupyter-chat/src/components/input/attach-button.tsx b/packages/jupyter-chat/src/components/input/attach-button.tsx index 335d80c..b7769c9 100644 --- a/packages/jupyter-chat/src/components/input/attach-button.tsx +++ b/packages/jupyter-chat/src/components/input/attach-button.tsx @@ -28,22 +28,21 @@ export function AttachButton(props: AttachButtonProps): JSX.Element { const tooltip = 'Add attachment'; const onclick = async () => { - FileDialog.getOpenFiles({ - title: 'Select files to attach', - manager: props.documentManager - }) - .then(result => { - if (result.value) { - result.value.forEach(file => { - if (file.type !== 'directory') { - props.onAttach({ type: 'file', value: file.path }); - } - }); - } - }) - .catch(e => { - console.warn('Error selecting files to attach', e); + try { + const files = await FileDialog.getOpenFiles({ + title: 'Select files to attach', + manager: props.documentManager }); + if (files.value) { + files.value.forEach(file => { + if (file.type !== 'directory') { + props.onAttach({ type: 'file', value: file.path }); + } + }); + } + } catch (e) { + console.warn('Error selecting files to attach', e); + } }; return ( diff --git a/packages/jupyter-chat/src/model.ts b/packages/jupyter-chat/src/model.ts index e0e097b..8fe78f4 100644 --- a/packages/jupyter-chat/src/model.ts +++ b/packages/jupyter-chat/src/model.ts @@ -563,7 +563,7 @@ export class ChatModel implements IChatModel { if (duplicateAttachment) { return; } - + this.inputAttachments.push(attachment); this._inputAttachmentsChanges.emit([...this.inputAttachments]); }; @@ -578,7 +578,7 @@ export class ChatModel implements IChatModel { if (attachmentIndex === -1) { return; } - + this.inputAttachments.splice(attachmentIndex, 1); this._inputAttachmentsChanges.emit([...this.inputAttachments]); };