mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix(core): prevent creating session every time in chat page (#13190)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved session handling in chat to prevent redundant session creation and ensure consistent assignment of session functions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -106,6 +106,9 @@ export const Component = () => {
|
||||
|
||||
const createSession = useCallback(
|
||||
async (options: Partial<BlockSuitePresets.AICreateSessionOptions> = {}) => {
|
||||
if (currentSession) {
|
||||
return currentSession;
|
||||
}
|
||||
const sessionId = await client.createSession({
|
||||
workspaceId,
|
||||
promptName: 'Chat With AFFiNE AI' satisfies PromptKey,
|
||||
@@ -117,7 +120,7 @@ export const Component = () => {
|
||||
setCurrentSession(session);
|
||||
return session;
|
||||
},
|
||||
[client, workspaceId]
|
||||
[client, currentSession, workspaceId]
|
||||
);
|
||||
|
||||
const togglePin = useCallback(async () => {
|
||||
@@ -204,10 +207,10 @@ export const Component = () => {
|
||||
confirmModal.closeConfirmModal,
|
||||
confirmModal.openConfirmModal
|
||||
);
|
||||
content.createSession = createSession;
|
||||
|
||||
if (!chatContent) {
|
||||
// initial values that won't change
|
||||
content.createSession = createSession;
|
||||
content.independentMode = true;
|
||||
content.onboardingOffsetY = -100;
|
||||
chatContainerRef.current?.append(content);
|
||||
|
||||
Reference in New Issue
Block a user