2026-07-16 06:19:58 -04:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { Search, Bell, Plus, Menu } from 'lucide-react';
|
2026-07-25 02:22:01 +00:00
|
|
|
import { usePathname } from 'next/navigation';
|
2026-07-16 06:19:58 -04:00
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
|
import { useSidebarStore } from '@/lib/stores/use-sidebar-store';
|
2026-07-25 02:22:01 +00:00
|
|
|
import { useCreateDialogStore } from '@/lib/stores/use-create-dialog-store';
|
2026-07-16 06:19:58 -04:00
|
|
|
import { CommandPalette } from '@/components/command-palette';
|
2026-07-29 19:47:09 +00:00
|
|
|
import { NotificationBell } from '@/components/notifications/notification-bell';
|
2026-07-16 06:19:58 -04:00
|
|
|
|
|
|
|
|
export function TopBar() {
|
2026-07-18 19:05:52 -04:00
|
|
|
const pathname = usePathname();
|
2026-07-16 06:19:58 -04:00
|
|
|
const { setMobileOpen } = useSidebarStore();
|
2026-07-25 02:22:01 +00:00
|
|
|
const openCreate = useCreateDialogStore((s) => s.openCreate);
|
|
|
|
|
|
|
|
|
|
function handleCreate() {
|
|
|
|
|
if (pathname.startsWith('/projects')) openCreate('project');
|
|
|
|
|
else if (pathname.startsWith('/habits')) openCreate('habit');
|
|
|
|
|
else if (pathname.startsWith('/tasks')) openCreate('task');
|
2026-07-31 01:06:04 +00:00
|
|
|
// On other pages (e.g. /settings) the topbar's "Quick add" button
|
|
|
|
|
// visually overlaps form action buttons (e.g. Domain "Add") because
|
|
|
|
|
// both are anchored top-right. Dispatching Cmd+K here would cause
|
|
|
|
|
// those form clicks to be mis-interpreted as opening the palette.
|
|
|
|
|
// So we no-op on those pages — the form buttons handle their own actions.
|
2026-07-25 02:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const label = pathname.startsWith('/projects') ? 'New project'
|
|
|
|
|
: pathname.startsWith('/habits') ? 'New habit'
|
|
|
|
|
: pathname.startsWith('/tasks') ? 'New task' : 'Quick add';
|
2026-07-16 06:19:58 -04:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<header className="sticky top-0 z-10 flex h-14 items-center gap-4 border-b bg-card px-6" role="banner">
|
2026-07-25 02:22:01 +00:00
|
|
|
<Button variant="ghost" size="icon" className="md:hidden" onClick={() => setMobileOpen(true)} aria-label="Open navigation menu">
|
2026-07-16 06:19:58 -04:00
|
|
|
<Menu className="h-5 w-5" />
|
|
|
|
|
</Button>
|
|
|
|
|
<div className="flex-1 md:max-w-sm">
|
2026-07-25 02:22:01 +00:00
|
|
|
<Button variant="outline" className="w-full justify-start text-muted-foreground" onClick={() => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'k', metaKey: true }))} aria-label="Open search (Cmd+K)">
|
2026-07-16 06:19:58 -04:00
|
|
|
<Search className="mr-2 h-4 w-4" aria-hidden="true" />
|
2026-07-25 02:22:01 +00:00
|
|
|
Search or jump to... <kbd className="ml-auto pointer-events-none inline-flex h-5 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground">⌘K</kbd>
|
2026-07-16 06:19:58 -04:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="ml-auto flex items-center gap-2">
|
2026-07-31 01:06:04 +00:00
|
|
|
{(pathname.startsWith('/projects') ||
|
|
|
|
|
pathname.startsWith('/habits') ||
|
|
|
|
|
pathname.startsWith('/tasks')) && (
|
|
|
|
|
<Button variant="outline" size="sm" onClick={handleCreate} aria-label={label === 'Quick add' ? 'Quick add' : `Create ${label.toLowerCase()}`}>
|
|
|
|
|
<Plus className="mr-1 h-4 w-4" aria-hidden="true" />
|
|
|
|
|
{label}
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2026-07-29 19:27:24 +00:00
|
|
|
<NotificationBell />
|
2026-07-16 06:19:58 -04:00
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
<CommandPalette />
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|