Refactor session list with card component and date grouping

This commit is contained in:
Chris Scott committed 2026-01-03 00:51:05 -05:00
1 parent 6af39af424
commit 4b175604e9
3 files changed
+132 -54

No files matched your search

@@ -32,7 +32,7 @@ export function RepoDetailHeader({
const isNotMainBranch = currentBranch && currentBranch !== "main" && currentBranch !== "master"
return (
<div className="flex-shrink-0 z-10 border-b border-border bg-gradient-to-b from-background via-background to-background backdrop-blur-sm px-4 py-2">
<div className="flex-shrink-0 z-10 bg-gradient-to-b from-background via-background to-background backdrop-blur-sm px-4 py-2">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3 min-w-0">
<BackButton />
@@ -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<HTMLButtonElement>) => void;
}
export const SessionCard = ({
session,
isSelected,
isActive,
onSelect,
onToggleSelection,
onDelete,
}: SessionCardProps) => {
return (
<Card
className={`p-3 cursor-pointer transition-all ${
isSelected
? "border-blue-500 shadow-lg shadow-blue-900/30 dark:shadow-blue-900/30 bg-accent"
: isActive
? "bg-accent border-border"
: "bg-card border-border hover:bg-accent hover:border-border"
} hover:shadow-lg`}
onClick={() => onSelect(session.id)}
>
<div className="flex items-start justify-between gap-2">
<div className="flex items-start gap-2 flex-1 min-w-0">
<Checkbox
checked={isSelected}
onCheckedChange={(checked) => {
onToggleSelection(checked === true);
}}
onClick={(e) => {
e.stopPropagation();
}}
className="w-5 h-5 flex-shrink-0 mt-0.5"
/>
<div className="flex-1 min-w-0">
<h3 className="text-base font-semibold text-orange-600 dark:text-orange-400 truncate">
{session.title || "Untitled Session"}
</h3>
<div className="flex items-center gap-3 mt-1 text-xs text-muted-foreground">
<span className="flex items-center gap-1">
<Clock className="w-3 h-3" />
{formatDistanceToNow(new Date(session.time.updated), {
addSuffix: true,
})}
</span>
</div>
</div>
</div>
<button
className="h-6 w-6 p-0 text-foreground hover:text-red-600 dark:hover:text-red-400 bg-transparent border-none cursor-pointer"
onClick={onDelete}
>
<Trash2 className="w-4 h-4" />
</button>
</div>
</Card>
);
};
+61 -53
View File
@@ -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 <div className="p-4 text-sm text-muted-foreground">Loading sessions...</div>;
}
@@ -121,8 +133,8 @@ export const SessionList = ({
return (
<div className="flex flex-col h-full min-h-0">
<div className="p-4 flex-shrink-0">
<div className="flex items-center gap-3 mb-3">
<div className="px-4 pt-2 pb-3 flex-shrink-0 border-b border-border">
<div className="flex items-center gap-3">
<div className="relative flex-1">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
<Input
@@ -189,60 +201,56 @@ export const SessionList = ({
</div>
</div>
<div className="flex-1 overflow-y-auto px-4 pb-4 min-h-0">
<div className="flex-1 overflow-y-auto px-4 pt-3 pb-4 min-h-0">
<div className="flex flex-col gap-2">
{filteredSessions.length === 0 ? (
<div className="text-sm text-muted-foreground text-center py-4">
No sessions found
</div>
) : (
filteredSessions.map((session) => (
<Card
key={session.id}
className={`p-3 cursor-pointer transition-all ${
selectedSessions.has(session.id)
? "border-blue-500 shadow-lg shadow-blue-900/30 dark:shadow-blue-900/30 bg-accent"
: activeSessionID === session.id
? "bg-accent border-border"
: "bg-card border-border hover:bg-accent hover:border-border"
} hover:shadow-lg`}
onClick={() => onSelectSession(session.id)}
>
<div className="flex items-start justify-between gap-2">
<div className="flex items-start gap-2 flex-1 min-w-0">
<Checkbox
checked={selectedSessions.has(session.id)}
onCheckedChange={(checked) => {
toggleSessionSelection(session.id, checked === true);
}}
onClick={(e) => {
e.stopPropagation();
}}
className="w-5 h-5 flex-shrink-0 mt-0.5"
/>
<div className="flex-1 min-w-0">
<h3 className="text-sm font-medium text-foreground truncate">
{session.title || "Untitled Session"}
</h3>
<div className="flex items-center gap-3 mt-1 text-xs text-muted-foreground">
<span className="flex items-center gap-1">
<Clock className="w-3 h-3" />
{formatDistanceToNow(new Date(session.time.updated), {
addSuffix: true,
})}
</span>
</div>
</div>
<>
{todaySessions.length > 0 && (
<>
<div className="text-xs font-semibold text-muted-foreground px-1 py-2">
Today
</div>
<button
className="h-6 w-6 p-0 text-foreground hover:text-red-600 dark:hover:text-red-400 bg-transparent border-none cursor-pointer"
onClick={(e) => handleDelete(session.id, e)}
>
<Trash2 className="w-4 h-4" />
</button>
</div>
</Card>
))
{todaySessions.map((session) => (
<SessionCard
key={session.id}
session={session}
isSelected={selectedSessions.has(session.id)}
isActive={activeSessionID === session.id}
onSelect={onSelectSession}
onToggleSelection={(selected) => {
toggleSessionSelection(session.id, selected);
}}
onDelete={(e) => handleDelete(session.id, e)}
/>
))}
</>
)}
{olderSessions.length > 0 && (
<>
<div className="text-xs font-semibold text-muted-foreground px-1 py-2 mt-2">
Older
</div>
{olderSessions.map((session) => (
<SessionCard
key={session.id}
session={session}
isSelected={selectedSessions.has(session.id)}
isActive={activeSessionID === session.id}
onSelect={onSelectSession}
onToggleSelection={(selected) => {
toggleSessionSelection(session.id, selected);
}}
onDelete={(e) => handleDelete(session.id, e)}
/>
))}
</>
)}
</>
)}
</div>
</div>