mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 10:45:57 +08:00
fix(core): chat history not show in independent page (#13069)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added the ability to reload the current AI chat session, clearing and reinitializing the chat context. * Introduced a function to close the chat history menu in the AI chat toolbar. * Enabled seamless opening of specific chat sessions from the chat toolbar, with improved loading state handling and error feedback. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -308,6 +308,11 @@ export class AIChatContent extends SignalWatcher(
|
||||
this.closePreviewPanel(true);
|
||||
}
|
||||
|
||||
public reloadSession() {
|
||||
this.reset();
|
||||
this.initChatContent().catch(console.error);
|
||||
}
|
||||
|
||||
public openPreviewPanel(content?: TemplateResult<1>) {
|
||||
this.showPreviewPanel = true;
|
||||
if (content) this.previewPanelContent = content;
|
||||
|
||||
@@ -186,4 +186,8 @@ export class AIChatToolbar extends WithDisposable(ShadowlessElement) {
|
||||
closeOnClickAway: true,
|
||||
});
|
||||
};
|
||||
|
||||
public closeHistoryMenu() {
|
||||
this.abortController?.abort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ export const Component = () => {
|
||||
null
|
||||
);
|
||||
const [isTogglingPin, setIsTogglingPin] = useState(false);
|
||||
const [isOpeningSession, setIsOpeningSession] = useState(false);
|
||||
const chatContainerRef = useRef<HTMLDivElement>(null);
|
||||
const chatToolContainerRef = useRef<HTMLDivElement>(null);
|
||||
const widthSignalRef = useRef<Signal<number>>(signal(0));
|
||||
@@ -109,6 +110,25 @@ export const Component = () => {
|
||||
}
|
||||
}, [client, createSession, currentSession, isTogglingPin, workspaceId]);
|
||||
|
||||
const onOpenSession = useCallback(
|
||||
(sessionId: string) => {
|
||||
if (isOpeningSession) return;
|
||||
setIsOpeningSession(true);
|
||||
client
|
||||
.getSession(workspaceId, sessionId)
|
||||
.then(session => {
|
||||
setCurrentSession(session);
|
||||
chatContent?.reloadSession();
|
||||
chatTool?.closeHistoryMenu();
|
||||
})
|
||||
.catch(console.error)
|
||||
.finally(() => {
|
||||
setIsOpeningSession(false);
|
||||
});
|
||||
},
|
||||
[chatContent, chatTool, client, isOpeningSession, workspaceId]
|
||||
);
|
||||
|
||||
// create a temp doc/host for ai-chat-content
|
||||
useEffect(() => {
|
||||
let tempDoc: Doc | null = null;
|
||||
@@ -187,6 +207,9 @@ export const Component = () => {
|
||||
}
|
||||
|
||||
tool.session = currentSession;
|
||||
tool.workspaceId = workspaceId;
|
||||
tool.docDisplayConfig = docDisplayConfig;
|
||||
tool.onOpenSession = onOpenSession;
|
||||
|
||||
tool.onNewSession = () => {
|
||||
if (!currentSession) return;
|
||||
@@ -204,7 +227,16 @@ export const Component = () => {
|
||||
chatToolContainerRef.current.append(tool);
|
||||
setChatTool(tool);
|
||||
}
|
||||
}, [chatContent, chatTool, currentSession, isHeaderProvided, togglePin]);
|
||||
}, [
|
||||
chatContent,
|
||||
chatTool,
|
||||
currentSession,
|
||||
docDisplayConfig,
|
||||
isHeaderProvided,
|
||||
onOpenSession,
|
||||
togglePin,
|
||||
workspaceId,
|
||||
]);
|
||||
|
||||
const onChatContainerRef = useCallback((node: HTMLDivElement) => {
|
||||
if (node) {
|
||||
|
||||
Reference in New Issue
Block a user