mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
Add a docked desktop tool panel with an icon rail, driven by the shared panel URL param, and keep the mobile dialogs and drawers. Extract dialog bodies into reusable content components, rename the walkthrough dialog to a sheet, and make walkthrough generation asynchronous with client polling.
126 lines
6.0 KiB
TypeScript
126 lines
6.0 KiB
TypeScript
import { useNavigate } from "react-router-dom"
|
|
import { useQuery } from "@tanstack/react-query"
|
|
import { getRepo } from "@/api/repos"
|
|
import { useCreateSession } from "@/hooks/useOpenCode"
|
|
import { useDialogParam } from "@/hooks/useDialogParam"
|
|
import { useTerminalDialogParam } from "@/hooks/useOpenTerminal"
|
|
import { useSSE } from "@/hooks/useSSE"
|
|
import { getSessionPath } from "@/lib/navigation"
|
|
import { Button } from "@/components/ui/button"
|
|
import { Header } from "@/components/ui/header"
|
|
import { SessionList } from "@/components/session/SessionList"
|
|
import { FileBrowserSheet } from "@/components/file-browser/FileBrowserSheet"
|
|
import { RepoMcpDialog } from "@/components/repo/RepoMcpDialog"
|
|
import { RepoSkillsDialog } from "@/components/repo/RepoSkillsDialog"
|
|
import { SourceControlPanel } from "@/components/source-control"
|
|
import { TerminalPanel } from "@/components/terminal/TerminalPanel"
|
|
import { PreviewPanel } from "@/components/preview/PreviewPanel"
|
|
import { ResetPermissionsDialog } from "@/components/repo/ResetPermissionsDialog"
|
|
import { PendingActionsGroup } from "@/components/notifications/PendingActionsGroup"
|
|
import { ToolSidePanel } from "@/components/navigation/ToolSidePanel"
|
|
import { useMobile } from "@/hooks/useMobile"
|
|
import { useToolPanel } from "@/hooks/useToolPanel"
|
|
import { Plus } from "lucide-react"
|
|
|
|
export function AssistantRedirect() {
|
|
const navigate = useNavigate()
|
|
const repoId = 0
|
|
const [fileBrowserOpen, setFileBrowserOpen] = useDialogParam('files')
|
|
const [mcpDialogOpen, setMcpDialogOpen] = useDialogParam('mcp')
|
|
const [skillsDialogOpen, setSkillsDialogOpen] = useDialogParam('skills')
|
|
const [sourceControlOpen, setSourceControlOpen] = useDialogParam('sourceControl')
|
|
const [terminalOpen, setTerminalOpen] = useTerminalDialogParam()
|
|
const [previewOpen, setPreviewOpen] = useDialogParam('preview')
|
|
const [resetPermissionsOpen, setResetPermissionsOpen] = useDialogParam('resetPermissions')
|
|
const docked = !useMobile()
|
|
const toolPanel = useToolPanel(docked)
|
|
|
|
const { data: repo, isLoading: repoLoading, error: repoError } = useQuery({
|
|
queryKey: ["repo", repoId],
|
|
queryFn: () => getRepo(repoId),
|
|
})
|
|
|
|
const assistantDirectory = repo?.fullPath
|
|
|
|
useSSE(assistantDirectory)
|
|
|
|
const createSessionMutation = useCreateSession(assistantDirectory, (session) => {
|
|
navigate(getSessionPath(repoId, session.id))
|
|
})
|
|
|
|
const handleCreateSession = async () => {
|
|
await createSessionMutation.mutateAsync({ agent: undefined })
|
|
}
|
|
|
|
return (
|
|
<div className="flex h-dvh max-h-dvh min-w-0">
|
|
<div className="flex-1 min-w-0 h-dvh max-h-dvh overflow-hidden bg-gradient-to-br from-background via-background to-background flex flex-col pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-0">
|
|
<Header>
|
|
<Header.BackButton to="/" />
|
|
<Header.Title>Assistant</Header.Title>
|
|
<Header.Actions>
|
|
<div className="flex items-center gap-1">
|
|
<PendingActionsGroup />
|
|
</div>
|
|
<Button onClick={() => handleCreateSession()} disabled={!assistantDirectory || createSessionMutation.isPending} size="sm" className="hidden sm:inline-flex bg-primary hover:bg-primary-hover text-primary-foreground transition-all duration-200 hover:scale-105">
|
|
<Plus className="w-4 h-4 mr-2" />
|
|
<span>New Session</span>
|
|
</Button>
|
|
<Button onClick={() => handleCreateSession()} disabled={!assistantDirectory || createSessionMutation.isPending} aria-label="New Session" size="sm" className="sm:hidden h-10 w-10 p-0 bg-primary hover:bg-primary-hover text-primary-foreground transition-all duration-200 hover:scale-105">
|
|
<Plus className="w-5 h-5" />
|
|
</Button>
|
|
</Header.Actions>
|
|
</Header>
|
|
<div className="flex-1 flex flex-col min-h-0">
|
|
{repoError ? (
|
|
<div className="p-4 text-sm text-muted-foreground">Failed to load Assistant sessions</div>
|
|
) : repoLoading || !repo?.fullPath ? (
|
|
<div className="p-4 text-sm text-muted-foreground">Loading Assistant sessions...</div>
|
|
) : (
|
|
<SessionList
|
|
directory={assistantDirectory}
|
|
onSelectSession={(sessionId) => navigate(getSessionPath(repoId, sessionId))}
|
|
/>
|
|
)}
|
|
</div>
|
|
{assistantDirectory && (
|
|
<>
|
|
<FileBrowserSheet isOpen={!docked && fileBrowserOpen} onClose={() => setFileBrowserOpen(false)} basePath={repo?.localPath} repoName="Assistant" repoId={repoId} />
|
|
<RepoMcpDialog open={!docked && mcpDialogOpen} onOpenChange={setMcpDialogOpen} directory={assistantDirectory} />
|
|
{assistantDirectory ? (
|
|
<RepoSkillsDialog
|
|
open={!docked && skillsDialogOpen}
|
|
onOpenChange={setSkillsDialogOpen}
|
|
repoId={repoId}
|
|
sessionId="assistant-session"
|
|
directory={assistantDirectory}
|
|
/>
|
|
) : (
|
|
<RepoSkillsDialog
|
|
open={!docked && skillsDialogOpen}
|
|
onOpenChange={setSkillsDialogOpen}
|
|
repoId={repoId}
|
|
/>
|
|
)}
|
|
<SourceControlPanel repoId={repoId} isOpen={!docked && sourceControlOpen} onClose={() => setSourceControlOpen(false)} currentBranch={repo?.currentBranch || repo?.branch || "main"} repoName="Assistant" />
|
|
<TerminalPanel repoId={0} directory={assistantDirectory} isOpen={!docked && terminalOpen} onClose={() => setTerminalOpen(false)} />
|
|
<PreviewPanel isOpen={!docked && previewOpen} onClose={() => setPreviewOpen(false)} directory={assistantDirectory} />
|
|
<ResetPermissionsDialog open={resetPermissionsOpen} onOpenChange={setResetPermissionsOpen} repoId={repoId} />
|
|
</>
|
|
)}
|
|
</div>
|
|
{docked && (
|
|
<ToolSidePanel
|
|
panel={toolPanel}
|
|
repoId={repoId}
|
|
sessionId="assistant-session"
|
|
directory={assistantDirectory}
|
|
repoDirectory={assistantDirectory}
|
|
filesBasePath={repo?.localPath}
|
|
currentBranch={repo?.currentBranch || repo?.branch || "main"}
|
|
/>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|