"use client"; import { Archive, ChevronLeft, ChevronRight, PanelRightOpen, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { useThreads, ThreadWithTasks } from "@/providers/Thread"; import { useQueryState, parseAsString } from "nuqs"; import { useState } from "react"; import { ThreadItem } from "./thread-item"; const THREADS_PER_PAGE = 10; // More threads per page in sidebar // TODO: Clarify Language about Threads and Tasks in the TaskListSidebar component interface TaskListSidebarProps { onCollapse?: () => void; } export default function TaskListSidebar({ onCollapse }: TaskListSidebarProps) { const [taskId, setTaskId] = useQueryState("taskId", parseAsString); const [threadId, setThreadId] = useQueryState("threadId", parseAsString); const [currentPage, setCurrentPage] = useState(0); const { threads, threadsLoading } = useThreads(); // Handle thread navigation const handleThreadClick = (thread: ThreadWithTasks) => { setThreadId(thread.thread_id); setTaskId(null); }; // Sort threads by creation date (newest first) - already done in provider const sortedThreads = threads; const totalThreads = sortedThreads.length; const totalPages = Math.ceil(totalThreads / THREADS_PER_PAGE); const startIndex = currentPage * THREADS_PER_PAGE; const endIndex = startIndex + THREADS_PER_PAGE; const paginatedThreads = sortedThreads.slice(startIndex, endIndex); return (

Threads

{totalThreads} total threads

{onCollapse && ( )}
{threadsLoading ? (

Loading threads...

) : paginatedThreads.length > 0 ? (
{paginatedThreads.map((thread) => ( ))}
) : (

No threads found

)}
{totalPages > 1 && (
Page {currentPage + 1} of {totalPages}
)}
); }