Files
PaperClipAI/ui/src/components/SidebarProjectTasks.tsx
T
Devin FoleyandPaperclip 3dffb2c9dd Fix project sidebar navigation and pinned task expansion (#22264)
Open recent and pinned projects on Tasks and share their expandable task list.
Keep project pin and reorder controls at the header. Preserve unread markers
and monitoring status through the existing full issue response.

Verified 82 focused tests, UI typecheck, production build, token gates,
and 58 successful CI checks. Greptile is 5/5 with all threads resolved.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-11-18 17:38:38 -08:00

45 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useId, useState, type ReactNode } from "react";
import { useQuery } from "@tanstack/react-query";
import { ChevronRight } from "lucide-react";
import type { Issue, Project } from "@paperclipai/shared";
import { issuesApi } from "@/api/issues";
import { queryKeys } from "@/lib/queryKeys";
import { cn } from "@/lib/utils";
import { taskStatusIconProps } from "@/lib/task-status-presentation";
import { RecentTaskNavItem } from "./RecentTaskNavItem";
import { StatusIcon } from "./StatusIcon";
export function SidebarProjectTasks({ project, userId, children, renderTask }: {
project: Pick<Project, "id" | "companyId" | "name">;
userId?: string | null;
children: ReactNode;
renderTask?: (task: Issue) => ReactNode;
}) {
const [expanded, setExpanded] = useState(false);
const contentId = useId();
const { data: tasks, isPending, error } = useQuery({
queryKey: [...queryKeys.issues.listByProject(project.companyId, project.id), "sidebar-tasks", userId ?? "__local_board__"],
queryFn: ({ signal }) => issuesApi.list(project.companyId, {
projectId: project.id, includeReadState: true, limit: 12, sortField: "updated", sortDir: "desc",
}, { signal }),
enabled: expanded,
});
return <div>
<div className="flex min-w-0 items-center">
<div className="relative min-w-0 flex-1">{children}</div>
<button type="button" aria-label={`${expanded ? "Collapse" : "Expand"} ${project.name}`} aria-expanded={expanded} aria-controls={contentId}
className="mr-2 flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-sidebar-accent focus-visible:ring-2 focus-visible:ring-ring"
onClick={() => setExpanded(previous => !previous)}>
<ChevronRight aria-hidden className={cn("size-3.5 transition-transform", expanded && "rotate-90")} />
</button>
</div>
{expanded && <div id={contentId} className="ml-5 border-l border-border pl-1">
{isPending ? <p className="px-3 py-2 text-xs text-muted-foreground" role="status">Loading tasks…</p>
: error ? <p className="px-3 py-2 text-xs text-muted-foreground" role="alert">Couldn’t load tasks.</p>
: tasks?.length ? tasks.map(task => <div key={task.id}>{renderTask ? renderTask(task)
: <RecentTaskNavItem className="design-sidebar-item" task={task} label={task.title} iconNode={<StatusIcon {...taskStatusIconProps(task)} />} />}</div>)
: <p className="px-3 py-2 text-xs text-muted-foreground">No tasks yet.</p>}
</div>}
</div>;
}