Skip to content

Commit

Permalink
Use await to select files
Browse files Browse the repository at this point in the history
Co-authored-by: David L. Qiu <44106031+dlqqq@users.noreply.github.com>
  • Loading branch information
brichet and dlqqq committed Feb 6, 2025
1 parent 104709d commit a96b7e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
29 changes: 14 additions & 15 deletions packages/jupyter-chat/src/components/input/attach-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions packages/jupyter-chat/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ export class ChatModel implements IChatModel {
if (duplicateAttachment) {
return;
}

this.inputAttachments.push(attachment);
this._inputAttachmentsChanges.emit([...this.inputAttachments]);
};
Expand All @@ -578,7 +578,7 @@ export class ChatModel implements IChatModel {
if (attachmentIndex === -1) {
return;
}

this.inputAttachments.splice(attachmentIndex, 1);
this._inputAttachmentsChanges.emit([...this.inputAttachments]);
};
Expand Down

0 comments on commit a96b7e5

Please sign in to comment.