From 88a43cdd65926fc746e04e93151f734e2fade783 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Sun, 17 May 2026 16:46:34 +0530 Subject: [PATCH] refactor: enhance ConnectToolsBanner functionality and update sidebar navigation handling --- .../components/assistant-ui/thread.tsx | 144 ++++++++++-------- .../layout/ui/sidebar/MobileSidebar.tsx | 1 + .../components/layout/ui/sidebar/Sidebar.tsx | 15 +- 3 files changed, 94 insertions(+), 66 deletions(-) diff --git a/surfsense_web/components/assistant-ui/thread.tsx b/surfsense_web/components/assistant-ui/thread.tsx index a3709911a..60c4a4d25 100644 --- a/surfsense_web/components/assistant-ui/thread.tsx +++ b/surfsense_web/components/assistant-ui/thread.tsx @@ -261,7 +261,10 @@ const BANNER_CONNECTORS = [ const BANNER_DISMISSED_KEY = "surfsense-connect-tools-banner-dismissed"; -const ConnectToolsBanner: FC<{ isThreadEmpty: boolean }> = ({ isThreadEmpty }) => { +const ConnectToolsBanner: FC<{ + isThreadEmpty: boolean; + onVisibleChange?: (visible: boolean) => void; +}> = ({ isThreadEmpty, onVisibleChange }) => { const { data: connectors } = useAtomValue(connectorsAtom); const setConnectorDialogOpen = useSetAtom(connectorDialogOpenAtom); const [dismissed, setDismissed] = useState(() => { @@ -270,8 +273,13 @@ const ConnectToolsBanner: FC<{ isThreadEmpty: boolean }> = ({ isThreadEmpty }) = }); const hasConnectors = (connectors?.length ?? 0) > 0; + const isVisible = !dismissed && !hasConnectors && isThreadEmpty; - if (dismissed || hasConnectors || !isThreadEmpty) return null; + useEffect(() => { + onVisibleChange?.(isVisible); + }, [isVisible, onVisibleChange]); + + if (!isVisible) return null; const handleDismiss = (e: React.MouseEvent) => { e.stopPropagation(); @@ -280,42 +288,41 @@ const ConnectToolsBanner: FC<{ isThreadEmpty: boolean }> = ({ isThreadEmpty }) = }; return ( -
-
- - -
+
+ +
+ + {BANNER_CONNECTORS.map(({ type }, i) => ( + + + {getConnectorIcon(type, "size-3")} + + + ))} + +
); }; @@ -426,6 +433,7 @@ const Composer: FC = () => { const isThreadEmpty = useAuiState(({ thread }) => thread.isEmpty); const isThreadRunning = useAuiState(({ thread }) => thread.isRunning); + const [connectToolsTrayVisible, setConnectToolsTrayVisible] = useState(false); const currentPlaceholder = COMPOSER_PLACEHOLDER; @@ -735,32 +743,42 @@ const Composer: FC = () => { />
)} -
- - {clipboardInitialText && ( - setClipboardInitialText(undefined)} - /> - )} -
- +
+
+ + {clipboardInitialText && ( + setClipboardInitialText(undefined)} + /> + )} +
+ +
+ +
- - - +
); diff --git a/surfsense_web/components/layout/ui/sidebar/MobileSidebar.tsx b/surfsense_web/components/layout/ui/sidebar/MobileSidebar.tsx index 12809ec22..02fa666be 100644 --- a/surfsense_web/components/layout/ui/sidebar/MobileSidebar.tsx +++ b/surfsense_web/components/layout/ui/sidebar/MobileSidebar.tsx @@ -210,6 +210,7 @@ export function MobileSidebar({ } : undefined } + onNavigate={() => onOpenChange(false)} announcementUnreadCount={announcementUnreadCount} onLogout={onLogout} pageUsage={pageUsage} diff --git a/surfsense_web/components/layout/ui/sidebar/Sidebar.tsx b/surfsense_web/components/layout/ui/sidebar/Sidebar.tsx index 540a3dcc1..d290373dc 100644 --- a/surfsense_web/components/layout/ui/sidebar/Sidebar.tsx +++ b/surfsense_web/components/layout/ui/sidebar/Sidebar.tsx @@ -1,6 +1,6 @@ "use client"; -import { CreditCard, SquarePen, Zap } from "lucide-react"; +import { CreditCard, Dot, SquarePen, Zap } from "lucide-react"; import Link from "next/link"; import { useParams } from "next/navigation"; import { useTranslations } from "next-intl"; @@ -83,6 +83,7 @@ interface SidebarProps { onManageMembers?: () => void; onUserSettings?: () => void; onAnnouncements?: () => void; + onNavigate?: () => void; announcementUnreadCount?: number; onLogout?: () => void; pageUsage?: PageUsage; @@ -119,6 +120,7 @@ export function Sidebar({ onManageMembers, onUserSettings, onAnnouncements, + onNavigate, announcementUnreadCount = 0, onLogout, pageUsage, @@ -344,6 +346,7 @@ export function Sidebar({ pageUsage={pageUsage} isCollapsed={isCollapsed} hasNavSectionAbove={footerNavItems.length > 0} + onNavigate={onNavigate} /> {renderUserProfile && ( @@ -367,10 +370,12 @@ function SidebarUsageFooter({ pageUsage, isCollapsed, hasNavSectionAbove = false, + onNavigate, }: { pageUsage?: PageUsage; isCollapsed: boolean; hasNavSectionAbove?: boolean; + onNavigate?: () => void; }) { const params = useParams(); const searchSpaceId = params?.search_space_id ?? ""; @@ -424,6 +429,7 @@ function SidebarUsageFooter({
@@ -436,14 +442,17 @@ function SidebarUsageFooter({ Buy More - - $1/1k · $1/1M + + $1/1k + + $1/1M