Spaces:
Sleeping
Sleeping
Fix bug around chat deletion (#54)
Browse files
phd-advisor-frontend/src/components/Sidebar.js
CHANGED
|
@@ -27,7 +27,8 @@ const Sidebar = ({
|
|
| 27 |
isMobileOpen = false,
|
| 28 |
onMobileToggle,
|
| 29 |
onNavigateToCanvas,
|
| 30 |
-
refreshTrigger
|
|
|
|
| 31 |
}) => {
|
| 32 |
const { config } = useAppConfig();
|
| 33 |
const canvasLabel = config?.app?.title ? `${config.app.title} Canvas` : 'Canvas';
|
|
@@ -141,7 +142,7 @@ const Sidebar = ({
|
|
| 141 |
if (response.ok) {
|
| 142 |
setChatSessions(prev => prev.filter(session => session.id !== sessionId));
|
| 143 |
if (currentSessionId === sessionId) {
|
| 144 |
-
|
| 145 |
}
|
| 146 |
}
|
| 147 |
} catch (error) {
|
|
|
|
| 27 |
isMobileOpen = false,
|
| 28 |
onMobileToggle,
|
| 29 |
onNavigateToCanvas,
|
| 30 |
+
refreshTrigger,
|
| 31 |
+
onCurrentSessionDeleted
|
| 32 |
}) => {
|
| 33 |
const { config } = useAppConfig();
|
| 34 |
const canvasLabel = config?.app?.title ? `${config.app.title} Canvas` : 'Canvas';
|
|
|
|
| 142 |
if (response.ok) {
|
| 143 |
setChatSessions(prev => prev.filter(session => session.id !== sessionId));
|
| 144 |
if (currentSessionId === sessionId) {
|
| 145 |
+
onCurrentSessionDeleted?.();
|
| 146 |
}
|
| 147 |
}
|
| 148 |
} catch (error) {
|
phd-advisor-frontend/src/pages/ChatPage.js
CHANGED
|
@@ -261,6 +261,17 @@ const handleSelectSession = async (sessionId) => {
|
|
| 261 |
await loadChatSession(sessionId);
|
| 262 |
};
|
| 263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
// Handle creating new chat from sidebar
|
| 265 |
const handleNewChat = async (sessionId = null) => {
|
| 266 |
if (sessionId) {
|
|
@@ -746,6 +757,7 @@ const handleNewChat = async (sessionId = null) => {
|
|
| 746 |
currentSessionId={currentSessionId}
|
| 747 |
onSelectSession={handleSelectSession}
|
| 748 |
onNewChat={handleNewChat}
|
|
|
|
| 749 |
onSignOut={onSignOut}
|
| 750 |
authToken={authToken}
|
| 751 |
onSidebarToggle={handleSidebarToggle}
|
|
|
|
| 261 |
await loadChatSession(sessionId);
|
| 262 |
};
|
| 263 |
|
| 264 |
+
// Sidebar deleted the currently-active chat. Clear local state without
|
| 265 |
+
// creating a replacement session.
|
| 266 |
+
const handleCurrentSessionDeleted = () => {
|
| 267 |
+
setCurrentSessionId(null);
|
| 268 |
+
setCurrentSessionTitle('');
|
| 269 |
+
setMessages([]);
|
| 270 |
+
setReplyingTo(null);
|
| 271 |
+
setThinkingAdvisors([]);
|
| 272 |
+
setUploadedDocuments([]);
|
| 273 |
+
};
|
| 274 |
+
|
| 275 |
// Handle creating new chat from sidebar
|
| 276 |
const handleNewChat = async (sessionId = null) => {
|
| 277 |
if (sessionId) {
|
|
|
|
| 757 |
currentSessionId={currentSessionId}
|
| 758 |
onSelectSession={handleSelectSession}
|
| 759 |
onNewChat={handleNewChat}
|
| 760 |
+
onCurrentSessionDeleted={handleCurrentSessionDeleted}
|
| 761 |
onSignOut={onSignOut}
|
| 762 |
authToken={authToken}
|
| 763 |
onSidebarToggle={handleSidebarToggle}
|