From 2b87b7bb7539cca8498f904252bbb2937efa1d25 Mon Sep 17 00:00:00 2001 From: MananTank Date: Mon, 12 May 2025 20:54:35 +0000 Subject: [PATCH] [NEB-246] Nebula: handle aborted session with no messages (#7025) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR focuses on enhancing the `ChatSidebar`, `useSessionsWithLocalOverrides`, and `ChatPageContent` components. It improves session handling, updates the chat sidebar title, and adds a user-friendly message for sessions without messages. ### Detailed summary - Updated `title` prop in `` to default to "Untitled Chat". - Merged new sessions with existing ones in `useSessionsWithLocalOverrides`. - Introduced a message and icon for sessions with no messages in `ChatPageContent`. - Conditional rendering of `` based on message availability. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .../(app)/components/ChatPageContent.tsx | 45 ++++++++++++++----- .../(app)/components/ChatSidebar.tsx | 2 +- .../hooks/useSessionsWithLocalOverrides.ts | 14 +++++- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx b/apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx index e0d28857a65..4bca9787c17 100644 --- a/apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx +++ b/apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx @@ -9,7 +9,7 @@ import { DialogTitle, } from "@/components/ui/dialog"; import { useThirdwebClient } from "@/constants/thirdweb.client"; -import { ArrowRightIcon } from "lucide-react"; +import { ArrowRightIcon, MessageSquareXIcon } from "lucide-react"; import Link from "next/link"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { @@ -263,8 +263,11 @@ export function ChatPageContent(props: { const showEmptyState = !userHasSubmittedMessage && messages.length === 0 && + !props.session && !props.initialParams?.q; + const sessionWithNoMessages = props.session && messages.length === 0; + const connectedWalletsMeta: WalletMeta[] = connectedWallets.map((x) => ({ address: x.getAccount()?.address || "", walletId: x.id, @@ -318,17 +321,35 @@ export function ChatPageContent(props: { ) : (
- + {sessionWithNoMessages && ( +
+
+
+ +
+

+ No messages found +

+

+ This session was aborted before receiving any messages +

+
+
+ )} + + {messages.length > 0 && ( + + )}
diff --git a/apps/dashboard/src/app/nebula-app/(app)/hooks/useSessionsWithLocalOverrides.ts b/apps/dashboard/src/app/nebula-app/(app)/hooks/useSessionsWithLocalOverrides.ts index eb8cd56ed43..c1e46724a42 100644 --- a/apps/dashboard/src/app/nebula-app/(app)/hooks/useSessionsWithLocalOverrides.ts +++ b/apps/dashboard/src/app/nebula-app/(app)/hooks/useSessionsWithLocalOverrides.ts @@ -7,7 +7,19 @@ export function useSessionsWithLocalOverrides( ) { const newAddedSessions = useStore(newSessionsStore); const deletedSessions = useStore(deletedSessionsStore); - return [...newAddedSessions, ..._sessions].filter((s) => { + const mergedSessions = [..._sessions]; + + for (const session of newAddedSessions) { + // if adding a new session that has same id as existing session, update the existing session + const index = mergedSessions.findIndex((s) => s.id === session.id); + if (index !== -1) { + mergedSessions[index] = session; + } else { + mergedSessions.push(session); + } + } + + return mergedSessions.filter((s) => { return !deletedSessions.some((d) => d === s.id); }); }