Skip to content

Commit

Permalink
fix: optimize discard cases (#6850)
Browse files Browse the repository at this point in the history
  • Loading branch information
donteatfriedrice committed Apr 23, 2024
1 parent df506a1 commit ef224ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/blocks/src/root-block/widgets/ai-panel/ai-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ export class AffineAIPanelWidget extends WidgetElement {
this.config?.discardCallback?.();
};

private _clickOutside = () => {
switch (this.state) {
case 'hidden':
return;
case 'error':
this.hide();
break;
default:
this.discard();
}
};

toggle = (reference: ReferenceElement, input?: string) => {
if (input) {
this._inputText = input;
Expand Down Expand Up @@ -160,11 +172,6 @@ export class AffineAIPanelWidget extends WidgetElement {
};

discard = (callback: () => void = this._discardCallback) => {
if (this.state === 'hidden') return;
if (this.state === 'error') {
callback();
return;
}
this._clearDiscardModal();
this._discardModal = toggleDiscardModal(callback);
};
Expand Down Expand Up @@ -261,10 +268,9 @@ export class AffineAIPanelWidget extends WidgetElement {
if (
e.target !== this._discardModal &&
e.target !== this &&
!this.contains(e.target as Node) &&
this.state !== 'generating'
!this.contains(e.target as Node)
) {
this.discard();
this._clickOutside();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class AIPanelInput extends WithDisposable(LitElement) {
@keydown=${(e: KeyboardEvent) => {
if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) {
e.preventDefault();
e.stopPropagation();
this._sendToAI();
}
}}
Expand Down

0 comments on commit ef224ef

Please sign in to comment.