import { useState } from "react";
import { setIssueAssignees, setIssueLabels, setIssueLock } from "~/fns/labels";
import { useAction } from "~/hooks/use-action";
import { Avatar } from "~/ui/Avatar";
import { LabelChip } from "~/ui/LabelChip";
import { Button } from "~/ui/Button";
import { ThreadSubscription } from "./ThreadSubscription";
import { SidebarSection } from "~/ui/Heading";
type Props = {
owner: string;
repo: string;
number: number;
canMaintain: boolean;
locked: boolean;
labels: Array<{ id: string; name: string; color: string }>;
allLabels: Array<{ id: string; name: string; color: string }>;
assignees: Array<{ name: string }>;
assignable: string[];
children?: React.ReactNode;
};
function Section({ title, onEdit, children }: { title: string; onEdit?: () => void; children: React.ReactNode }) {
return (
Edit
)
}
>
{children}
);
}
function Picker({
options,
selected,
onSave,
pending,
}: {
options: string[];
selected: string[];
onSave: (values: string[]) => void;
pending: boolean;
}) {
const [values, setValues] = useState(new Set(selected));
return (
{options.length === 0 &&
Nothing to choose from.
}
{options.map((option) => (
))}
);
}
export function IssueSidebar({
owner,
repo,
number,
canMaintain,
locked,
labels,
allLabels,
assignees,
assignable,
children,
}: Props) {
const [editing, setEditing] = useState<"labels" | "assignees" | null>(null);
const saveLabels = useAction(setIssueLabels);
const saveAssignees = useAction(setIssueAssignees);
const lock = useAction(setIssueLock);
const toggle = (section: "labels" | "assignees") => setEditing((current) => (current === section ? null : section));
return (
);
}