mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +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(
|
const createSession = useCallback(
|
||||||
async (options: Partial<BlockSuitePresets.AICreateSessionOptions> = {}) => {
|
async (options: Partial<BlockSuitePresets.AICreateSessionOptions> = {}) => {
|
||||||
|
if (currentSession) {
|
||||||
|
return currentSession;
|
||||||
|
}
|
||||||
const sessionId = await client.createSession({
|
const sessionId = await client.createSession({
|
||||||
workspaceId,
|
workspaceId,
|
||||||
promptName: 'Chat With AFFiNE AI' satisfies PromptKey,
|
promptName: 'Chat With AFFiNE AI' satisfies PromptKey,
|
||||||
@@ -117,7 +120,7 @@ export const Component = () => {
|
|||||||
setCurrentSession(session);
|
setCurrentSession(session);
|
||||||
return session;
|
return session;
|
||||||
},
|
},
|
||||||
[client, workspaceId]
|
[client, currentSession, workspaceId]
|
||||||
);
|
);
|
||||||
|
|
||||||
const togglePin = useCallback(async () => {
|
const togglePin = useCallback(async () => {
|
||||||
@@ -204,10 +207,10 @@ export const Component = () => {
|
|||||||
confirmModal.closeConfirmModal,
|
confirmModal.closeConfirmModal,
|
||||||
confirmModal.openConfirmModal
|
confirmModal.openConfirmModal
|
||||||
);
|
);
|
||||||
|
content.createSession = createSession;
|
||||||
|
|
||||||
if (!chatContent) {
|
if (!chatContent) {
|
||||||
// initial values that won't change
|
// initial values that won't change
|
||||||
content.createSession = createSession;
|
|
||||||
content.independentMode = true;
|
content.independentMode = true;
|
||||||
content.onboardingOffsetY = -100;
|
content.onboardingOffsetY = -100;
|
||||||
chatContainerRef.current?.append(content);
|
chatContainerRef.current?.append(content);
|
||||||
|
|||||||
Reference in New Issue
Block a user