fix(editor): chat panel render warning (#9446)
Fixed the updated warning of both `chat-panel` and `chat-panel-messages` 
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
|||||||
UnauthorizedError,
|
UnauthorizedError,
|
||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
||||||
import { css, html, nothing, type PropertyValues } from 'lit';
|
import { css, html, nothing } from 'lit';
|
||||||
import { property, query, state } from 'lit/decorators.js';
|
import { property, query, state } from 'lit/decorators.js';
|
||||||
import { repeat } from 'lit/directives/repeat.js';
|
import { repeat } from 'lit/directives/repeat.js';
|
||||||
import { styleMap } from 'lit/directives/style-map.js';
|
import { styleMap } from 'lit/directives/style-map.js';
|
||||||
@@ -139,25 +139,6 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
|
|||||||
@state()
|
@state()
|
||||||
accessor showChatCards = true;
|
accessor showChatCards = true;
|
||||||
|
|
||||||
protected override updated(changedProperties: PropertyValues) {
|
|
||||||
if (changedProperties.has('host')) {
|
|
||||||
const { disposables } = this;
|
|
||||||
|
|
||||||
disposables.add(
|
|
||||||
this.host.selection.slots.changed.on(() => {
|
|
||||||
this._selectionValue = this.host.selection.value;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const docModeService = this.host.std.get(DocModeProvider);
|
|
||||||
disposables.add(
|
|
||||||
docModeService.onPrimaryModeChange(
|
|
||||||
() => this.requestUpdate(),
|
|
||||||
this.host.doc.id
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private _renderAIOnboarding() {
|
private _renderAIOnboarding() {
|
||||||
return this.isLoading ||
|
return this.isLoading ||
|
||||||
!this.host?.doc.awarenessStore.getFlag('enable_ai_onboarding')
|
!this.host?.doc.awarenessStore.getFlag('enable_ai_onboarding')
|
||||||
@@ -284,13 +265,16 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
|
|||||||
|
|
||||||
override connectedCallback() {
|
override connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
|
const { disposables } = this;
|
||||||
|
const docModeService = this.host.std.get(DocModeProvider);
|
||||||
|
|
||||||
Promise.resolve(AIProvider.userInfo)
|
Promise.resolve(AIProvider.userInfo)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.avatarUrl = res?.avatarUrl ?? '';
|
this.avatarUrl = res?.avatarUrl ?? '';
|
||||||
})
|
})
|
||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
this.disposables.add(
|
|
||||||
|
disposables.add(
|
||||||
AIProvider.slots.userInfo.on(userInfo => {
|
AIProvider.slots.userInfo.on(userInfo => {
|
||||||
const { status, error } = this.chatContextValue;
|
const { status, error } = this.chatContextValue;
|
||||||
this.avatarUrl = userInfo?.avatarUrl ?? '';
|
this.avatarUrl = userInfo?.avatarUrl ?? '';
|
||||||
@@ -303,12 +287,22 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
disposables.add(
|
||||||
this.disposables.add(
|
|
||||||
AIProvider.slots.toggleChatCards.on(({ visible }) => {
|
AIProvider.slots.toggleChatCards.on(({ visible }) => {
|
||||||
this.showChatCards = visible;
|
this.showChatCards = visible;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
disposables.add(
|
||||||
|
this.host.selection.slots.changed.on(() => {
|
||||||
|
this._selectionValue = this.host.selection.value;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
disposables.add(
|
||||||
|
docModeService.onPrimaryModeChange(
|
||||||
|
() => this.requestUpdate(),
|
||||||
|
this.host.doc.id
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderItem(item: ChatItem, isLast: boolean) {
|
renderItem(item: ChatItem, isLast: boolean) {
|
||||||
|
|||||||
@@ -191,8 +191,10 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
|
|||||||
|
|
||||||
protected override updated(_changedProperties: PropertyValues) {
|
protected override updated(_changedProperties: PropertyValues) {
|
||||||
if (_changedProperties.has('doc')) {
|
if (_changedProperties.has('doc')) {
|
||||||
this.chatContextValue.chatSessionId = null;
|
requestAnimationFrame(() => {
|
||||||
this._resetItems();
|
this.chatContextValue.chatSessionId = null;
|
||||||
|
this._resetItems();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user