mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(sidebar): add repo-grouped session navigation with live status (#361)
* feat(sidebar): add repo-grouped session navigation with live status - Add a searchable, collapsible session tree to the desktop sidebar, grouped by repository with pinned and time-bucketed ordering. - Track per-session busy, retry, and compact status in a shared store fed by the SSE event stream and scoped by directory. - Extract shared navigation components reused by the desktop tree and the mobile repo quick-switch sheet. - Show a Git tab and hide Schedules inside a repo on the mobile tab bar; add Repos and Assistant entries to the session More drawer. - Replace the CommitsTab local relative-time formatter with a shared formatShortRelativeTime util. * refactor(sidebar): unify session status tracking and navigation helpers * feat(sidebar): add collapsible sessions and menu sections * fix(sessions): keep specific live status over snapshot busy
This commit is contained in:
1 parent
1389e8e59c
commit
015a44a5f3
45 files changed
+3347
-763
No files matched your search
@@ -0,0 +1,132 @@
|
||||
import { useMemo, useState } from 'react'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import { Search } from 'lucide-react'
|
||||
import type { Repo } from '@/api/types'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { useNavigableRepos, useSidebarRepoGroups } from '@/hooks/useSidebarRepoGroups'
|
||||
import {
|
||||
NewSessionButton,
|
||||
RepoNavGroup,
|
||||
RepoSessionNavList,
|
||||
SearchClearButton,
|
||||
SessionNavRow,
|
||||
SessionNavStatus,
|
||||
} from '@/components/navigation/RepoSessionNav'
|
||||
import { getActiveRepoId, isCurrentSessionItem, isRepoReady } from '@/components/navigation/sidebar-session-tree'
|
||||
|
||||
function SessionSearchInput({
|
||||
hasActiveSearch,
|
||||
onSubmit,
|
||||
onClear,
|
||||
}: {
|
||||
hasActiveSearch: boolean
|
||||
onSubmit: (query: string) => void
|
||||
onClear: () => void
|
||||
}) {
|
||||
const [draft, setDraft] = useState('')
|
||||
|
||||
const clear = () => {
|
||||
setDraft('')
|
||||
onClear()
|
||||
}
|
||||
|
||||
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault()
|
||||
onSubmit(draft.trim())
|
||||
} else if (event.key === 'Escape') {
|
||||
clear()
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<Search className="absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
value={draft}
|
||||
onChange={(event) => setDraft(event.target.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
aria-label="Search sessions"
|
||||
placeholder="Search sessions..."
|
||||
autoComplete="off"
|
||||
name="sidebar-session-search"
|
||||
className="h-8 pl-8 pr-9"
|
||||
/>
|
||||
{(draft.length > 0 || hasActiveSearch) && <SearchClearButton onClear={clear} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SessionSearchResults({ repos, search }: { repos: Repo[]; search: string }) {
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const searchableRepos = useMemo(() => repos.filter(isRepoReady), [repos])
|
||||
const { groups, isLoading, isError } = useSidebarRepoGroups({ repos: searchableRepos, search })
|
||||
const matchingGroups = groups.filter((group) => group.items.length > 0)
|
||||
|
||||
if (isLoading) return <SessionNavStatus>Loading sessions...</SessionNavStatus>
|
||||
if (isError) return <SessionNavStatus>Failed to load sessions</SessionNavStatus>
|
||||
if (matchingGroups.length === 0) return <SessionNavStatus>No sessions found</SessionNavStatus>
|
||||
|
||||
return (
|
||||
<>
|
||||
{matchingGroups.map((group) => (
|
||||
<RepoNavGroup
|
||||
key={group.repo.id}
|
||||
name={group.label}
|
||||
branch={group.branchLabel}
|
||||
isWorktree={group.repo.isWorktree}
|
||||
isOpen
|
||||
isCurrent={group.repo.id === getActiveRepoId(location.pathname)}
|
||||
onOpenRepo={() => navigate(`/repos/${group.repo.id}`)}
|
||||
actions={<NewSessionButton repo={group.repo} onOpenSession={navigate} />}
|
||||
>
|
||||
{group.items.map((item) => (
|
||||
<SessionNavRow
|
||||
key={item.key}
|
||||
item={item}
|
||||
isCurrent={isCurrentSessionItem(item, location.pathname)}
|
||||
onSelect={navigate}
|
||||
/>
|
||||
))}
|
||||
</RepoNavGroup>
|
||||
))}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export function DesktopSessionTree() {
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const [search, setSearch] = useState('')
|
||||
const { repos, isLoading } = useNavigableRepos()
|
||||
|
||||
return (
|
||||
<div className="flex min-h-0 flex-1 flex-col">
|
||||
<div className="px-2 pb-2">
|
||||
<SessionSearchInput
|
||||
hasActiveSearch={search.length > 0}
|
||||
onSubmit={setSearch}
|
||||
onClear={() => setSearch('')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div role="region" aria-label="Session navigator" className="min-h-0 flex-1 overflow-y-auto pb-2">
|
||||
{isLoading ? (
|
||||
<SessionNavStatus>Loading repos...</SessionNavStatus>
|
||||
) : search ? (
|
||||
<SessionSearchResults repos={repos} search={search} />
|
||||
) : (
|
||||
<RepoSessionNavList
|
||||
repos={repos}
|
||||
activeRepoId={getActiveRepoId(location.pathname)}
|
||||
isVisible
|
||||
onOpenRepo={(repoId) => navigate(`/repos/${repoId}`)}
|
||||
onSelectSession={navigate}
|
||||
renderActions={(repo) => <NewSessionButton repo={repo} onOpenSession={navigate} />}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user