2026-03-06 17:22:59 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
2026-03-20 17:35:06 +07:00
|
|
|
DropdownMenuSeparator,
|
2026-03-06 17:22:59 +02:00
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from '@/components/ui/dropdown-menu';
|
|
|
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
|
|
|
|
import {
|
|
|
|
|
RiCheckLine,
|
2026-03-20 01:01:03 +02:00
|
|
|
RiChatNewLine,
|
2026-03-06 17:22:59 +02:00
|
|
|
RiEqualizer2Line,
|
2026-03-20 01:01:03 +02:00
|
|
|
RiFolderAddLine,
|
2026-03-06 17:22:59 +02:00
|
|
|
RiSearchLine,
|
2026-03-20 01:01:03 +02:00
|
|
|
RiCloseLine,
|
2026-03-20 17:35:06 +07:00
|
|
|
RiContractUpDownLine,
|
|
|
|
|
RiExpandUpDownLine,
|
2026-03-20 18:58:13 +02:00
|
|
|
RiStickyNoteLine,
|
2026-03-06 17:22:59 +02:00
|
|
|
} from '@remixicon/react';
|
2026-03-22 22:31:29 +02:00
|
|
|
import { ArrowsMerge } from '@/components/icons/ArrowsMerge';
|
2026-03-20 18:58:13 +02:00
|
|
|
import type { ProjectRef } from '@/lib/openchamberConfig';
|
2026-03-06 17:22:59 +02:00
|
|
|
import { useSessionDisplayStore } from '@/stores/useSessionDisplayStore';
|
2026-03-20 18:58:13 +02:00
|
|
|
import { ProjectNotesTodoPanel } from '../ProjectNotesTodoPanel';
|
2026-03-06 17:22:59 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
hideDirectoryControls: boolean;
|
|
|
|
|
handleOpenDirectoryDialog: () => void;
|
2026-03-20 01:01:03 +02:00
|
|
|
handleNewSession: () => void;
|
2026-03-20 18:58:13 +02:00
|
|
|
useMobileNotesPanel: boolean;
|
|
|
|
|
projectNotesPanelOpen: boolean;
|
|
|
|
|
setProjectNotesPanelOpen: (open: boolean) => void;
|
|
|
|
|
activeProjectRefForHeader: ProjectRef | null;
|
|
|
|
|
activeProjectLabelForHeader: string | null;
|
2026-03-22 22:31:29 +02:00
|
|
|
canOpenMultiRun: boolean;
|
|
|
|
|
openMultiRunLauncher: () => void;
|
2026-03-20 18:58:13 +02:00
|
|
|
stableActiveProjectIsRepo: boolean;
|
2026-03-06 17:22:59 +02:00
|
|
|
headerActionIconClass: string;
|
|
|
|
|
reserveHeaderActionsSpace: boolean;
|
|
|
|
|
headerActionButtonClass: string;
|
|
|
|
|
isSessionSearchOpen: boolean;
|
|
|
|
|
setIsSessionSearchOpen: (open: boolean | ((prev: boolean) => boolean)) => void;
|
|
|
|
|
sessionSearchInputRef: React.RefObject<HTMLInputElement | null>;
|
|
|
|
|
sessionSearchQuery: string;
|
|
|
|
|
setSessionSearchQuery: (value: string) => void;
|
|
|
|
|
hasSessionSearchQuery: boolean;
|
|
|
|
|
searchMatchCount: number;
|
2026-03-20 17:35:06 +07:00
|
|
|
collapseAllProjects: () => void;
|
|
|
|
|
expandAllProjects: () => void;
|
2026-03-06 17:22:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function SidebarHeader(props: Props): React.ReactNode {
|
|
|
|
|
const {
|
|
|
|
|
hideDirectoryControls,
|
2026-03-20 01:01:03 +02:00
|
|
|
handleOpenDirectoryDialog,
|
|
|
|
|
handleNewSession,
|
2026-03-20 18:58:13 +02:00
|
|
|
useMobileNotesPanel,
|
|
|
|
|
projectNotesPanelOpen,
|
|
|
|
|
setProjectNotesPanelOpen,
|
|
|
|
|
activeProjectRefForHeader,
|
|
|
|
|
activeProjectLabelForHeader,
|
2026-03-22 22:31:29 +02:00
|
|
|
canOpenMultiRun,
|
|
|
|
|
openMultiRunLauncher,
|
2026-03-20 18:58:13 +02:00
|
|
|
stableActiveProjectIsRepo,
|
2026-03-06 17:22:59 +02:00
|
|
|
headerActionIconClass,
|
|
|
|
|
reserveHeaderActionsSpace,
|
|
|
|
|
headerActionButtonClass,
|
|
|
|
|
isSessionSearchOpen,
|
|
|
|
|
setIsSessionSearchOpen,
|
|
|
|
|
sessionSearchInputRef,
|
|
|
|
|
sessionSearchQuery,
|
|
|
|
|
setSessionSearchQuery,
|
|
|
|
|
hasSessionSearchQuery,
|
|
|
|
|
searchMatchCount,
|
2026-03-20 17:35:06 +07:00
|
|
|
collapseAllProjects,
|
|
|
|
|
expandAllProjects,
|
2026-03-06 17:22:59 +02:00
|
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
const displayMode = useSessionDisplayStore((state) => state.displayMode);
|
|
|
|
|
const setDisplayMode = useSessionDisplayStore((state) => state.setDisplayMode);
|
|
|
|
|
|
|
|
|
|
if (hideDirectoryControls) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-03-20 01:01:03 +02:00
|
|
|
<div className="select-none flex-shrink-0 px-2.5 py-1">
|
|
|
|
|
{reserveHeaderActionsSpace ? (
|
|
|
|
|
<div className="flex h-auto min-h-8 flex-col gap-1">
|
|
|
|
|
<div className="flex h-8 items-center justify-between gap-2">
|
|
|
|
|
<div className="flex items-center gap-1.5">
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={handleOpenDirectoryDialog}
|
|
|
|
|
className={headerActionButtonClass}
|
|
|
|
|
aria-label="Add project"
|
2026-03-06 17:22:59 +02:00
|
|
|
>
|
2026-03-20 01:01:03 +02:00
|
|
|
<RiFolderAddLine className={headerActionIconClass} />
|
|
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="bottom" sideOffset={4}><p>Add project</p></TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
2026-03-06 17:22:59 +02:00
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-03-20 01:01:03 +02:00
|
|
|
onClick={handleNewSession}
|
|
|
|
|
className={headerActionButtonClass}
|
|
|
|
|
aria-label="New session"
|
2026-03-06 17:22:59 +02:00
|
|
|
>
|
2026-03-20 01:01:03 +02:00
|
|
|
<RiChatNewLine className={headerActionIconClass} />
|
2026-03-06 17:22:59 +02:00
|
|
|
</button>
|
2026-03-20 01:01:03 +02:00
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="bottom" sideOffset={4}><p>New session</p></TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</div>
|
2026-03-06 17:22:59 +02:00
|
|
|
|
2026-03-20 01:01:03 +02:00
|
|
|
<div className="flex items-center gap-1.5">
|
2026-03-22 22:31:29 +02:00
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={openMultiRunLauncher}
|
|
|
|
|
className={headerActionButtonClass}
|
|
|
|
|
aria-label="New multi-run"
|
|
|
|
|
disabled={!canOpenMultiRun}
|
|
|
|
|
>
|
|
|
|
|
<ArrowsMerge className={headerActionIconClass} />
|
|
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="bottom" sideOffset={4}><p>New multi-run</p></TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
|
2026-03-20 18:58:13 +02:00
|
|
|
{useMobileNotesPanel ? (
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setProjectNotesPanelOpen(true)}
|
|
|
|
|
className={headerActionButtonClass}
|
|
|
|
|
aria-label="Project notes"
|
|
|
|
|
disabled={!activeProjectRefForHeader}
|
|
|
|
|
>
|
|
|
|
|
<RiStickyNoteLine className={headerActionIconClass} />
|
|
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="bottom" sideOffset={4}><p>Project notes</p></TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
) : (
|
|
|
|
|
<DropdownMenu open={projectNotesPanelOpen} onOpenChange={setProjectNotesPanelOpen} modal={false}>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className={headerActionButtonClass}
|
|
|
|
|
aria-label="Project notes"
|
|
|
|
|
disabled={!activeProjectRefForHeader}
|
|
|
|
|
>
|
|
|
|
|
<RiStickyNoteLine className={headerActionIconClass} />
|
|
|
|
|
</button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="bottom" sideOffset={4}><p>Project notes</p></TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
<DropdownMenuContent align="start" className="w-[420px] max-w-[min(92vw,420px)] p-0">
|
|
|
|
|
<ProjectNotesTodoPanel
|
|
|
|
|
projectRef={activeProjectRefForHeader}
|
|
|
|
|
projectLabel={activeProjectLabelForHeader}
|
|
|
|
|
canCreateWorktree={stableActiveProjectIsRepo}
|
|
|
|
|
onActionComplete={() => setProjectNotesPanelOpen(false)}
|
|
|
|
|
/>
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-03-20 01:01:03 +02:00
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setIsSessionSearchOpen((prev) => !prev)}
|
|
|
|
|
className={headerActionButtonClass}
|
|
|
|
|
aria-label="Search sessions"
|
|
|
|
|
aria-expanded={isSessionSearchOpen}
|
|
|
|
|
>
|
|
|
|
|
<RiSearchLine className={headerActionIconClass} />
|
|
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="bottom" sideOffset={4}><p>Search sessions</p></TooltipContent>
|
|
|
|
|
</Tooltip>
|
2026-03-06 17:22:59 +02:00
|
|
|
|
2026-03-20 01:01:03 +02:00
|
|
|
<DropdownMenu>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
2026-03-06 17:22:59 +02:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className={headerActionButtonClass}
|
2026-03-20 01:01:03 +02:00
|
|
|
aria-label="Session display mode"
|
2026-03-06 17:22:59 +02:00
|
|
|
>
|
2026-03-20 01:01:03 +02:00
|
|
|
<RiEqualizer2Line className={headerActionIconClass} />
|
2026-03-06 17:22:59 +02:00
|
|
|
</button>
|
2026-03-20 01:01:03 +02:00
|
|
|
</DropdownMenuTrigger>
|
2026-03-06 17:22:59 +02:00
|
|
|
</TooltipTrigger>
|
2026-03-20 01:01:03 +02:00
|
|
|
<TooltipContent side="bottom" sideOffset={4}><p>Display mode</p></TooltipContent>
|
2026-03-06 17:22:59 +02:00
|
|
|
</Tooltip>
|
2026-03-20 01:01:03 +02:00
|
|
|
<DropdownMenuContent align="end" className="min-w-[160px]">
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
onClick={() => setDisplayMode('default')}
|
|
|
|
|
className="flex items-center justify-between"
|
|
|
|
|
>
|
|
|
|
|
<span>Default</span>
|
|
|
|
|
{displayMode === 'default' ? <RiCheckLine className="h-4 w-4 text-primary" /> : null}
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
onClick={() => setDisplayMode('minimal')}
|
|
|
|
|
className="flex items-center justify-between"
|
|
|
|
|
>
|
|
|
|
|
<span>Minimal</span>
|
|
|
|
|
{displayMode === 'minimal' ? <RiCheckLine className="h-4 w-4 text-primary" /> : null}
|
|
|
|
|
</DropdownMenuItem>
|
2026-03-20 17:35:06 +07:00
|
|
|
<DropdownMenuSeparator />
|
|
|
|
|
<DropdownMenuItem onClick={collapseAllProjects} className="flex items-center gap-2">
|
|
|
|
|
<RiContractUpDownLine className="h-4 w-4" />
|
|
|
|
|
<span>Collapse all</span>
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem onClick={expandAllProjects} className="flex items-center gap-2">
|
|
|
|
|
<RiExpandUpDownLine className="h-4 w-4" />
|
|
|
|
|
<span>Expand all</span>
|
|
|
|
|
</DropdownMenuItem>
|
2026-03-20 01:01:03 +02:00
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-06 17:22:59 +02:00
|
|
|
|
2026-03-20 01:01:03 +02:00
|
|
|
{isSessionSearchOpen ? (
|
|
|
|
|
<div className="pb-1">
|
|
|
|
|
<div className="mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80">
|
|
|
|
|
{hasSessionSearchQuery ? (
|
|
|
|
|
<span>{searchMatchCount} {searchMatchCount === 1 ? 'match' : 'matches'}</span>
|
|
|
|
|
) : <span />}
|
|
|
|
|
<span>Esc to clear</span>
|
2026-03-06 17:22:59 +02:00
|
|
|
</div>
|
2026-03-20 01:01:03 +02:00
|
|
|
<div className="relative">
|
|
|
|
|
<RiSearchLine className="pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
|
|
|
|
<input
|
|
|
|
|
ref={sessionSearchInputRef}
|
|
|
|
|
value={sessionSearchQuery}
|
|
|
|
|
onChange={(event) => setSessionSearchQuery(event.target.value)}
|
|
|
|
|
placeholder="Search sessions..."
|
|
|
|
|
className="h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-8 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50"
|
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
|
if (event.key === 'Escape') {
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
if (hasSessionSearchQuery) {
|
|
|
|
|
setSessionSearchQuery('');
|
|
|
|
|
} else {
|
|
|
|
|
setIsSessionSearchOpen(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{sessionSearchQuery.length > 0 ? (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setSessionSearchQuery('')}
|
|
|
|
|
className="absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"
|
|
|
|
|
aria-label="Clear search"
|
|
|
|
|
>
|
|
|
|
|
<RiCloseLine className="h-3.5 w-3.5" />
|
|
|
|
|
</button>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-06 17:22:59 +02:00
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|