Skip to content

Commit ddd0bf9

Browse files
author
dolphin
committed
fix: some bugfix
1 parent 0f124fc commit ddd0bf9

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

src/frontend/client/src/pages/appChat/AppChatEntry.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export default function AppChatEntry() {
2626
const fromDelete = (location.state as { fromDelete?: boolean } | null)?.fromDelete === true;
2727
const resolvedRef = useRef(false);
2828

29+
// Flow-level info (name / logo / description) is loaded by SideNav's useAppSidebar
30+
// hook into currentAppInfoState, so the sidebar card is populated here too.
31+
2932
const buildQs = useCallback(() => {
3033
const from = new URLSearchParams(location.search).get('from');
3134
return from ? `?from=${from}` : '';

src/frontend/client/src/pages/appChat/SideNav.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export function SideNav() {
7474

7575
// Current conversation's app data
7676
const chatState = useRecoilValue(currentChatState);
77-
const flowData = chatState?.flow;
7877

7978
// Sidebar hook for conversation list and actions
8079
const {
@@ -84,8 +83,14 @@ export function SideNav() {
8483
createNewChat,
8584
shareApp,
8685
fetchConversations,
86+
currentApp,
8787
} = useAppSidebar();
8888

89+
// Fall back to `currentApp` (populated by AppChatEntry) when no chat is active —
90+
// e.g. right after deleting the last conversation, chatState is cleared but the
91+
// sidebar card should still show the app's name / logo / description.
92+
const flowData = chatState?.flow ?? currentApp;
93+
8994
return (
9095
<div className="w-[280px] h-full bg-white border-r border-[#ececec] flex flex-col gap-4 px-3 py-5 overflow-hidden text-[#212121]">
9196
{/* Top back button */}

src/frontend/client/src/pages/appChat/hooks/useAppSidebar.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useCallback, useEffect, useRef, useState } from 'react';
22
import { useLocation, useNavigate, useParams } from 'react-router-dom';
3-
import { useRecoilState, useRecoilValue } from 'recoil';
3+
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
44
import { NotificationSeverity } from '~/common';
5-
import type { AppConversation, ConversationGroup } from '~/@types/app';
6-
import { getAppConversationsApi } from '~/api/apps';
5+
import type { AppConversation, AppItem, ConversationGroup } from '~/@types/app';
6+
import { getAppConversationsApi, getAssistantDetailApi, getFlowApi } from '~/api/apps';
77
import { groupConversationsByTime, getAppShareUrl } from '~/pages/apps/appUtils';
88
import { copyText } from '~/utils';
99
import { useToastContext } from '~/Providers';
@@ -15,6 +15,9 @@ import {
1515
import { generateUUID } from '~/utils';
1616
import { useLocalize } from '~/hooks';
1717

18+
// flow_type 5 === assistant; anything else (1 = skill, 10 = workflow) goes through getFlowApi.
19+
const FLOW_TYPE_ASSISTANT = 5;
20+
1821
/**
1922
* Hook for the app chat sidebar.
2023
* Handles: loading conversations, time grouping, new/switch conversation, sidebar toggle.
@@ -29,6 +32,7 @@ export function useAppSidebar() {
2932
showToastRef.current = showToast;
3033

3134
const currentApp = useRecoilValue(currentAppInfoState);
35+
const setCurrentApp = useSetRecoilState(currentAppInfoState);
3236
const [conversations, setConversations] = useRecoilState(appConversationsState);
3337
const [sidebarVisible, setSidebarVisible] = useRecoilState(sidebarVisibleState);
3438

@@ -128,6 +132,34 @@ export function useAppSidebar() {
128132
// This prevents re-triggering when the user creates a new chat or switches conversations.
129133
const hasAutoSelectedRef = useRef<string | null>(null);
130134

135+
// Fetch flow-level info (name / logo / description) into currentAppInfoState so
136+
// the sidebar card stays populated even when no chat is active — e.g. right after
137+
// deleting the active conversation, chatsState briefly loses the flow reference.
138+
useEffect(() => {
139+
if (!flowId || !flowType) return;
140+
const numericType = Number(flowType);
141+
(async () => {
142+
try {
143+
const res = numericType === FLOW_TYPE_ASSISTANT
144+
? await getAssistantDetailApi(flowId, undefined, true)
145+
: await getFlowApi(flowId, 'v1', undefined, true);
146+
if (res?.status_code !== 200) return;
147+
const data = res.data;
148+
if (!data) return;
149+
setCurrentApp({
150+
id: data.id ?? flowId,
151+
name: data.name ?? '',
152+
description: data.description ?? '',
153+
logo: data.logo ?? '',
154+
flow_type: Number(data.flow_type ?? numericType),
155+
user_id: data.user_id ?? '',
156+
} as AppItem);
157+
} catch {
158+
// silent — sidebar falls back to placeholder text
159+
}
160+
})();
161+
}, [flowId, flowType, setCurrentApp]);
162+
131163
// Auto-fetch on mount or flowId change, with one-time auto-select
132164
useEffect(() => {
133165
fetchConversations().then((list) => {

0 commit comments

Comments
 (0)