diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot-2/components/ChatSidebar/ChatSidebar.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot-2/components/ChatSidebar/ChatSidebar.tsx index a3f6992e02..631cc4d711 100644 --- a/autogpt_platform/frontend/src/app/(platform)/copilot-2/components/ChatSidebar/ChatSidebar.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/copilot-2/components/ChatSidebar/ChatSidebar.tsx @@ -1,18 +1,26 @@ "use client"; import { Sidebar, SidebarHeader, SidebarContent, SidebarFooter, SidebarTrigger, useSidebar } from "@/components/ui/sidebar"; import { cn } from "@/lib/utils"; -import { SparkleIcon, PlusIcon, SpinnerGapIcon } from "@phosphor-icons/react"; +import { SparkleIcon, PlusIcon, SpinnerGapIcon, ChatCircleIcon } from "@phosphor-icons/react"; import { motion } from "framer-motion"; import { useState } from "react"; import { parseAsString, useQueryState } from "nuqs"; -import { postV2CreateSession } from "@/app/api/__generated__/endpoints/chat/chat"; +import { postV2CreateSession, useGetV2ListSessions, getGetV2ListSessionsQueryKey } from "@/app/api/__generated__/endpoints/chat/chat"; import { Button } from "@/components/atoms/Button/Button"; +import { useQueryClient } from "@tanstack/react-query"; export function ChatSidebar() { const { state } = useSidebar(); const isCollapsed = state === "collapsed"; const [isCreating, setIsCreating] = useState(false); - const [, setSessionId] = useQueryState("sessionId", parseAsString); + const [sessionId, setSessionId] = useQueryState("sessionId", parseAsString); + const queryClient = useQueryClient(); + + const { data: sessionsResponse, isLoading: isLoadingSessions } = useGetV2ListSessions( + { limit: 50 }, + ); + + const sessions = sessionsResponse?.status === 200 ? sessionsResponse.data.sessions : []; async function handleNewChat() { if (isCreating) return; @@ -23,12 +31,29 @@ export function ChatSidebar() { }); if (response.status === 200 && response.data?.id) { setSessionId(response.data.id); + queryClient.invalidateQueries({ queryKey: getGetV2ListSessionsQueryKey() }); } } finally { setIsCreating(false); } } + function handleSelectSession(id: string) { + setSessionId(id); + } + + function formatDate(dateString: string) { + const date = new Date(dateString); + const now = new Date(); + const diffMs = now.getTime() - date.getTime(); + const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24)); + + if (diffDays === 0) return "Today"; + if (diffDays === 1) return "Yesterday"; + if (diffDays < 7) return `${diffDays} days ago`; + return date.toLocaleDateString(); + } + return ( } } - +
- + {!isCollapsed && ( +
+ +
)} - > - {isCreating ? ( - - ) : ( - - )} - {!isCollapsed && {isCreating ? "Creating..." : "New Chat"}} - - {!isCollapsed &&
- - -
} -
- + + {!isCollapsed && ( +
+ {isLoadingSessions ? ( +
+ +
+ ) : sessions.length === 0 ? ( +

No conversations yet

+ ) : ( + sessions.map((session) => ( + + )) + )} +
+ )}
diff --git a/autogpt_platform/frontend/src/components/ui/sidebar.tsx b/autogpt_platform/frontend/src/components/ui/sidebar.tsx index 002544c7aa..6c5bb30450 100644 --- a/autogpt_platform/frontend/src/components/ui/sidebar.tsx +++ b/autogpt_platform/frontend/src/components/ui/sidebar.tsx @@ -27,8 +27,8 @@ import { const SIDEBAR_COOKIE_NAME = "sidebar_state" const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7 -const SIDEBAR_WIDTH = "16rem" -const SIDEBAR_WIDTH_MOBILE = "18rem" +const SIDEBAR_WIDTH = "20rem" +const SIDEBAR_WIDTH_MOBILE = "20rem" const SIDEBAR_WIDTH_ICON = "3rem" const SIDEBAR_KEYBOARD_SHORTCUT = "b"