From 4b175604e9530ddc3389a455f0f8d444d8c6087d Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Sat, 3 Jan 2026 00:51:05 -0500 Subject: [PATCH] Refactor session list with card component and date grouping --- .../components/layout/RepoDetailHeader.tsx | 2 +- .../src/components/session/SessionCard.tsx | 70 +++++++++++ .../src/components/session/SessionList.tsx | 114 ++++++++++-------- 3 files changed, 132 insertions(+), 54 deletions(-) create mode 100644 frontend/src/components/session/SessionCard.tsx diff --git a/frontend/src/components/layout/RepoDetailHeader.tsx b/frontend/src/components/layout/RepoDetailHeader.tsx index c35d8bd6..4f514fcb 100644 --- a/frontend/src/components/layout/RepoDetailHeader.tsx +++ b/frontend/src/components/layout/RepoDetailHeader.tsx @@ -32,7 +32,7 @@ export function RepoDetailHeader({ const isNotMainBranch = currentBranch && currentBranch !== "main" && currentBranch !== "master" return ( -
+
diff --git a/frontend/src/components/session/SessionCard.tsx b/frontend/src/components/session/SessionCard.tsx new file mode 100644 index 00000000..df99a8c9 --- /dev/null +++ b/frontend/src/components/session/SessionCard.tsx @@ -0,0 +1,70 @@ +import { Card } from "@/components/ui/card"; +import { Checkbox } from "@/components/ui/checkbox"; +import { Trash2, Clock } from "lucide-react"; +import { formatDistanceToNow } from "date-fns"; +import type { Session } from "@/api/types"; + +interface SessionCardProps { + session: Session; + isSelected: boolean; + isActive: boolean; + onSelect: (sessionID: string) => void; + onToggleSelection: (selected: boolean) => void; + onDelete: (e: React.MouseEvent) => void; +} + +export const SessionCard = ({ + session, + isSelected, + isActive, + onSelect, + onToggleSelection, + onDelete, +}: SessionCardProps) => { + return ( + onSelect(session.id)} + > +
+
+ { + onToggleSelection(checked === true); + }} + onClick={(e) => { + e.stopPropagation(); + }} + className="w-5 h-5 flex-shrink-0 mt-0.5" + /> +
+

+ {session.title || "Untitled Session"} +

+
+ + + {formatDistanceToNow(new Date(session.time.updated), { + addSuffix: true, + })} + +
+
+
+ +
+
+ ); +}; \ No newline at end of file diff --git a/frontend/src/components/session/SessionList.tsx b/frontend/src/components/session/SessionList.tsx index f6de64a0..a7cc20a0 100644 --- a/frontend/src/components/session/SessionList.tsx +++ b/frontend/src/components/session/SessionList.tsx @@ -1,13 +1,11 @@ import { useState, useMemo } from "react"; import { useSessions, useDeleteSession } from "@/hooks/useOpenCode"; -import { Card } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; -import { Checkbox } from "@/components/ui/checkbox"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; import { DeleteSessionDialog } from "./DeleteSessionDialog"; -import { Trash2, Clock, Search, MoreVertical } from "lucide-react"; -import { formatDistanceToNow } from "date-fns"; +import { SessionCard } from "./SessionCard"; +import { Trash2, Search, MoreVertical } from "lucide-react"; interface SessionListProps { opcodeUrl: string; @@ -52,6 +50,20 @@ export const SessionList = ({ return filtered.sort((a, b) => b.time.updated - a.time.updated); }, [sessions, searchQuery, directory]); + const todaySessions = useMemo(() => { + if (!filteredSessions) return []; + const today = new Date(); + today.setHours(0, 0, 0, 0); + return filteredSessions.filter((session) => new Date(session.time.updated) >= today); + }, [filteredSessions]); + + const olderSessions = useMemo(() => { + if (!filteredSessions) return []; + const today = new Date(); + today.setHours(0, 0, 0, 0); + return filteredSessions.filter((session) => new Date(session.time.updated) < today); + }, [filteredSessions]); + if (isLoading) { return
Loading sessions...
; } @@ -121,8 +133,8 @@ export const SessionList = ({ return (
-
-
+
+
-
+
{filteredSessions.length === 0 ? (
No sessions found
) : ( - filteredSessions.map((session) => ( - onSelectSession(session.id)} - > -
-
- { - toggleSessionSelection(session.id, checked === true); - }} - onClick={(e) => { - e.stopPropagation(); - }} - className="w-5 h-5 flex-shrink-0 mt-0.5" - /> -
-

- {session.title || "Untitled Session"} -

-
- - - {formatDistanceToNow(new Date(session.time.updated), { - addSuffix: true, - })} - -
-
+ <> + {todaySessions.length > 0 && ( + <> +
+ Today
- -
- - )) + {todaySessions.map((session) => ( + { + toggleSessionSelection(session.id, selected); + }} + onDelete={(e) => handleDelete(session.id, e)} + /> + ))} + + )} + + {olderSessions.length > 0 && ( + <> +
+ Older +
+ {olderSessions.map((session) => ( + { + toggleSessionSelection(session.id, selected); + }} + onDelete={(e) => handleDelete(session.id, e)} + /> + ))} + + )} + )}