import { createContext, useContext } from "react"; import { Link } from "../../lib/navigation"; import { ArchiveIcon, ChevronRightIcon, CopyIcon, CopyPlusIcon, EllipsisIcon, FolderIcon, InfoIcon, LinkIcon, PanelsTopLeftIcon, PinIcon, } from "lucide-react"; import { OpenPublishedSiteItem, useSiteActions, type SiteActions } from "../artifacts/site-actions"; import { RailTrailingMetadata } from "./session-row-content"; import { RAIL_ROW_OVERFLOW_TRIGGER_CLASS, RAIL_ROW_QUICK_ACTIONS_CLASS, RailRowQuickAction, } from "./rail-row-quick-actions"; import { Button } from "../../../ui/button"; import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuTrigger, } from "../../../ui/context-menu"; import { DropdownMenu, DropdownMenuCheck, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "../../../ui/dropdown-menu"; import { cn } from "../../lib/utils"; import { visualTreeDepth } from "../../lib/session-rail"; import type { RailAggregateStatus } from "../../lib/sessions-group"; import type { SessionSiteOrigin } from "../../lib/session-site-origin"; import type { Channel } from "../../types"; /** * Pin and archive for Site rows, in this person's own sidebar. Archive only * hides the row; the Site stays published. Absent where the client cannot * change sidebar state, and then the row offers no actions. Move files the * row in another project (null is Default), like a chat; absent where the * client predates it. */ export type SiteRowActions = { pin: (origin: SessionSiteOrigin, pinned: boolean) => void; archive: (origin: SessionSiteOrigin) => void; move?: | ((origin: SessionSiteOrigin, fromChannelId: string | null, channelId: string | null) => void) | undefined; }; export const SiteRowActionsContext = createContext(null); /** Drag payload of a Site row: `{ siteId, title, channelId }` as JSON. */ export const SITE_DRAG_TYPE = "application/x-opengeni-site"; export type SiteRowDragPayload = { siteId: string; title: string; channelId: string | null }; export function readSiteRowDragPayload(value: string): SiteRowDragPayload | null { try { const parsed = JSON.parse(value) as unknown; if (!parsed || typeof parsed !== "object") return null; const { siteId, title, channelId } = parsed as Record; if ( typeof siteId !== "string" || typeof title !== "string" || (channelId !== null && typeof channelId !== "string") ) return null; return { siteId, title, channelId }; } catch { return null; } } /** A Site's row in the rail: open the Site view, or disclose its conversations. */ export function SiteSessionGroupHeading({ origin, workspaceId, expanded, onToggle, summary, count, relativeTime, depth = 0, active = false, pinned = false, channelId, channels, }: { origin: SessionSiteOrigin; workspaceId: string; expanded: boolean; onToggle: () => void; summary: RailAggregateStatus; /** Conversations behind the row, loaded or not. */ count: number; relativeTime?: string | undefined; depth?: number | undefined; active?: boolean | undefined; /** This person pinned the Site in their sidebar. */ pinned?: boolean | undefined; /** The project this row is in (null is Default); undefined when it stands for every project. */ channelId?: string | null | undefined; /** Projects it can move to, as offered for chats. */ channels?: readonly Channel[] | undefined; }) { const actions = useContext(SiteRowActionsContext); // Held by the row, not its menu, so a duplicate still running when the // menu closes stays busy the next time it opens. const site = useSiteActions(workspaceId, origin); const move = actions?.move; // As for a chat row: listed only when there is a project to choose. const moveTargets = move && channelId !== undefined && channels && channels.length > 0 ? [{ id: null, name: "Default" }, ...channels] : []; const canMove = moveTargets.length > 0; const conversations = `${count} ${count === 1 ? "conversation" : "conversations"}`; // A Site without conversations is a plain row: nothing to disclose. const disclosable = count > 0 || expanded; const pinLabel = pinned ? "Unpin" : "Pin"; const row = (
0 ? { marginLeft: visualTreeDepth(depth) * 12 } : undefined} > {disclosable ? ( ) : null} 0 ? `, ${conversations}. ${summary.label}` : ""}`} // Drag onto a project to move the row there, like a chat row. draggable={canMove} onDragStart={(event) => { if (!canMove) { event.preventDefault(); return; } event.stopPropagation(); event.dataTransfer.effectAllowed = "move"; event.dataTransfer.setData( SITE_DRAG_TYPE, JSON.stringify({ siteId: origin.siteId, title: origin.title, channelId: channelId ?? null, } satisfies SiteRowDragPayload), ); }} className="flex h-full min-w-0 flex-1 items-center gap-1.5 rounded-sm outline-hidden focus-visible:ring-2 focus-visible:ring-ring/40 focus-visible:ring-offset-1 focus-visible:ring-offset-surface" >
); if (!actions) return row; return ( {row} ); } /** * A Site row's menu, the same for right-click and "…": what a chat row * offers that fits a Site (Copy link, Copy title, Pin, Archive, Move to * project), plus the Site's own: Duplicate, Site details and, once known to * be on the web, Open published Site (last, so nothing moves when it shows). Renaming has no place here: a Site is * named by what it publishes. */ function SiteRowMenuItems({ menu, origin, site, workspaceId, pinned, actions, moveTargets, channelId, }: { menu: "context" | "dropdown"; origin: SessionSiteOrigin; site: SiteActions; workspaceId: string; pinned: boolean; actions: SiteRowActions; moveTargets: readonly { id: string | null; name: string }[]; channelId: string | null | undefined; }) { const Item = (menu === "context" ? ContextMenuItem : DropdownMenuItem) as typeof DropdownMenuItem; const Separator = menu === "context" ? ContextMenuSeparator : DropdownMenuSeparator; const Label = menu === "context" ? ContextMenuLabel : DropdownMenuLabel; return ( <> Copy link Copy title actions.pin(origin, !pinned)}> {pinned ? "Unpin" : "Pin"} {site.duplicate ? ( {site.duplicate.busy ? "Duplicating…" : "Duplicate"} ) : null} Site details actions.archive(origin)}> Archive {/* Last, as it shows once the address has loaded: nothing above moves. */} {moveTargets.length > 0 ? ( <> {moveTargets.map((channel) => { const current = (channelId ?? null) === channel.id; return ( { if (!current) actions.move?.(origin, channelId ?? null, channel.id); }} > ); })} ) : null} ); }