import { ArrowLeft, GitBranch, Hash, ListTodo, MessagesSquare, Plus, } from "lucide-react"; import * as React from "react"; import { useAppNavigation } from "@/app/navigation/useAppNavigation"; import { useCreateChannelMutation } from "@/features/channels/hooks"; import { useCommunities } from "@/features/communities/useCommunities"; import { CreateChannelDialog } from "@/features/sidebar/ui/CreateChannelDialog"; import type { Channel } from "@/shared/api/types"; import { Button } from "@/shared/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/shared/ui/dialog"; import { useCreateProjectIssueMutation } from "../issueMutations"; import { useChannelProjectFeatures } from "../useChannelProjectFeatures"; import { CreateProjectWorkItemDialog } from "./CreateProjectWorkItemDialog"; import { ProjectIssuesPanel } from "./ProjectIssuesPanel"; import { ProjectRepositoryManagement } from "./ProjectRepositoryManagement"; type OpenTool = "tasks" | "breakouts" | "repositories" | null; export function ChannelProjectFeatureBar({ channel, currentPubkey, }: { channel: Channel; currentPubkey?: string; }) { const { activeCommunity } = useCommunities(); const { goChannel } = useAppNavigation(); const context = useChannelProjectFeatures({ channel, currentPubkey, relayUrl: activeCommunity?.relayUrl, }); const createChannelMutation = useCreateChannelMutation(); const createTaskMutation = useCreateProjectIssueMutation( context.primaryRepository, ); const [openTool, setOpenTool] = React.useState(null); const [createTaskOpen, setCreateTaskOpen] = React.useState(false); const [createChannelOpen, setCreateChannelOpen] = React.useState(false); const [selectedIssueId, setSelectedIssueId] = React.useState( null, ); if ( !context.project || !Object.values(context.enabled).some(Boolean) || channel.channelType === "dm" ) { return null; } const breakoutChannels = context.breakoutChannelIds.flatMap((channelId) => { const result = context.channels.find( (candidate) => candidate.id === channelId, ); return result ? [result] : []; }); return ( <> {selectedIssueId ? ( ) : null} } onOpenChange={(open) => { setOpenTool(open ? "tasks" : null); if (!open) setSelectedIssueId(null); }} open={openTool === "tasks"} testId="channel-tasks-dialog" title="Tasks" > {context.primaryRepository ? ( ) : ( Tasks are unavailable. )} { await createTaskMutation.mutateAsync(input); context.setFeatureEnabled("tasks", true); }} onOpenChange={setCreateTaskOpen} open={createTaskOpen} submitDisabled={!context.primaryRepository} title="Create task" titlePlaceholder="Task title" /> setCreateChannelOpen(true)} size="icon" type="button" variant="outline" > } onOpenChange={(open) => setOpenTool(open ? "breakouts" : null)} open={openTool === "breakouts"} testId="channel-breakouts-dialog" title="Breakout channels" > {breakoutChannels.length > 0 ? (
{breakoutChannels.map((breakoutChannel) => ( ))}
) : ( No breakout channels yet. )}
{ const createdChannel = await createChannelMutation.mutateAsync({ ...input, channelType: "stream", }); const section = context.ensureBreakoutSection(); if (!section) throw new Error("Could not create the channel group."); context.channelSections.assignChannel(createdChannel.id, section.id); context.setFeatureEnabled("breakouts", true); }} onOpenChange={setCreateChannelOpen} /> context.setFeatureEnabled("repositories", true)} project={context.project} projects={context.projects} repository={context.primaryRepository} showAccessManagement={false} /> ) : null } onOpenChange={(open) => setOpenTool(open ? "repositories" : null)} open={openTool === "repositories"} testId="channel-repositories-dialog" title="Related repositories" > {context.relatedRepositories.length > 0 ? (
{context.relatedRepositories.map((repository) => (
{repository.name}
))}
) : ( No related repositories yet. )}
); } function FeatureButton({ icon: Icon, label, onClick, testId, }: { icon: typeof ListTodo; label: string; onClick: () => void; testId: string; }) { return ( ); } function ToolDialog({ actions, children, onOpenChange, open, testId, title, }: { actions?: React.ReactNode; children: React.ReactNode; onOpenChange: (open: boolean) => void; open: boolean; testId: string; title: string; }) { return (
{title} {title} for this channel
{actions}
{children}
); } function EmptyState({ children }: { children: React.ReactNode }) { return

{children}

; }