"use client";
import { IconCircle, IconCircleCheck } from "@tabler/icons-react";
import { Badge } from "@kandev/ui/badge";
import { Spinner } from "@kandev/ui/spinner";
import { cn, formatRelativeTime } from "@/lib/utils";
import type { Issue } from "@/lib/types/gitlab";
import type { GitLabLaunchPayload, GitLabTaskPreset } from "./quick-task-launcher";
import { StartTaskMenu } from "./start-task-menu";
import { SubscriptionToggle } from "../subscription-toggle";
import { RowTitleLink } from "./row-title-link";
import { useTranslation } from "react-i18next";
type IssueListProps = {
items: Issue[];
loading: boolean;
error: string | null;
presets?: GitLabTaskPreset[];
onStartTask?: (payload: GitLabLaunchPayload) => void;
workspaceId?: string;
host?: string;
};
function IssueMilestoneChip({ milestone }: { milestone: string }) {
if (!milestone) return null;
return (
{milestone}
);
}
function IssueLabels({ labels }: { labels: string[] }) {
if (!labels?.length) return null;
return (
<>
{labels.slice(0, 4).map((l) => (
{l}
))}
{labels.length > 4 && (
+{labels.length - 4}
)}
>
);
}
function IssueRow({
issue,
presets,
onStartTask,
workspaceId,
host,
}: {
issue: Issue;
presets: GitLabTaskPreset[];
onStartTask?: IssueListProps["onStartTask"];
workspaceId?: string;
host?: string;
}) {
const { t } = useTranslation();
const isOpen = issue.state !== "closed";
const StateIcon = isOpen ? IconCircle : IconCircleCheck;
const stateClass = isOpen
? "text-emerald-600 dark:text-emerald-400"
: "text-purple-600 dark:text-purple-400";
return (
{issue.project_path}#{issue.iid}
ยท
{t("gitlab:byAuthorOpenedAgo", {
author: issue.author_username,
time: formatRelativeTime(issue.created_at),
})}
{workspaceId && host ? (
) : null}
{onStartTask ? (
onStartTask({ kind: "issue", issue, preset })}
/>
) : null}
);
}
function IssueListBody({
loading,
error,
items,
presets = [],
onStartTask,
workspaceId,
host,
}: IssueListProps) {
const { t } = useTranslation();
if (loading) {
return (
);
}
if (error) {
return {error}
;
}
if (items.length === 0) {
return (
{t("gitlab:noIssuesMatchThisFilter")}
);
}
return (
{items.map((issue) => (
))}
);
}
export function IssueList(props: IssueListProps) {
return (
);
}