mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 18:09:58 +08:00
fix(core): optimize request chat cards fn (#7331)
This commit is contained in:
@@ -18,10 +18,6 @@ export interface AIChatParams {
|
||||
autoSelect?: boolean;
|
||||
}
|
||||
|
||||
type RequestChatCardsElement = (
|
||||
chatPanel: HTMLElement
|
||||
) => Promise<ChatCards | null>;
|
||||
|
||||
export type ActionEventType =
|
||||
| 'started'
|
||||
| 'finished'
|
||||
@@ -76,8 +72,17 @@ export class AIProvider {
|
||||
return AIProvider.instance.toggleGeneralAIOnboarding;
|
||||
}
|
||||
|
||||
static get requestChatCardsElement() {
|
||||
return AIProvider.instance.requestChatCardsElement;
|
||||
static genRequestChatCardsFn(params: AIChatParams) {
|
||||
return async (chatPanel: HTMLElement) => {
|
||||
const chatCards: ChatCards | null = await new Promise(resolve =>
|
||||
requestAnimationFrame(() =>
|
||||
resolve(chatPanel.querySelector('chat-cards'))
|
||||
)
|
||||
);
|
||||
if (!chatCards) return;
|
||||
if (chatCards.temporaryParams) return;
|
||||
chatCards.temporaryParams = params;
|
||||
};
|
||||
}
|
||||
|
||||
private static readonly instance = new AIProvider();
|
||||
@@ -94,14 +99,6 @@ export class AIProvider {
|
||||
|
||||
private toggleGeneralAIOnboarding: ((value: boolean) => void) | null = null;
|
||||
|
||||
private readonly requestChatCardsElement: RequestChatCardsElement = (
|
||||
chatPanel: HTMLElement
|
||||
) => {
|
||||
return new Promise(resolve => {
|
||||
resolve(chatPanel.querySelector<ChatCards>('chat-cards'));
|
||||
});
|
||||
};
|
||||
|
||||
private readonly slots = {
|
||||
// use case: when user selects "continue in chat" in an ask ai result panel
|
||||
// do we need to pass the context to the chat panel?
|
||||
|
||||
Reference in New Issue
Block a user