mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
refactor: persist assistant repo in database with ID migration (#271)
This commit is contained in:
1 parent
0d384d6cf0
commit
8133b655b0
12 files changed
+188
-112
No files matched your search
@@ -8,8 +8,8 @@ import { cn, getRepoDisplayName } from '@/lib/utils'
|
||||
import { listRepos } from '@/api/repos'
|
||||
import { AddRepoDialog } from '@/components/repo/AddRepoDialog'
|
||||
import { FolderGit2, Check, Plus, House } from 'lucide-react'
|
||||
import { isAssistantPath, getAssistantPath } from '@/lib/navigation'
|
||||
import { useUrlParams } from '@/hooks/useUrlParams'
|
||||
import { ASSISTANT_REPO_ID } from '@opencode-manager/shared/utils'
|
||||
|
||||
interface RepoQuickSwitchSheetProps {
|
||||
isOpen: boolean
|
||||
@@ -23,13 +23,10 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [addRepoOpen, setAddRepoOpen] = useState(false)
|
||||
|
||||
const isAssistantRoute = useMemo(() => isAssistantPath(location.pathname), [location.pathname])
|
||||
|
||||
const activeRepoId = useMemo(() => {
|
||||
if (isAssistantRoute) return null
|
||||
const match = location.pathname.match(/^\/repos\/(\d+)/)
|
||||
return match ? Number(match[1]) : null
|
||||
}, [location.pathname, isAssistantRoute])
|
||||
}, [location.pathname])
|
||||
|
||||
const { data: repos, isLoading } = useQuery({
|
||||
queryKey: ['repos'],
|
||||
@@ -37,15 +34,20 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
enabled: isOpen,
|
||||
})
|
||||
|
||||
const regularRepos = useMemo(
|
||||
() => repos?.filter((r) => r.id !== ASSISTANT_REPO_ID) ?? null,
|
||||
[repos],
|
||||
)
|
||||
|
||||
const filteredRepos = useMemo(() => {
|
||||
if (!repos) return []
|
||||
const sorted = [...repos].sort((a, b) => (b.lastAccessedAt ?? 0) - (a.lastAccessedAt ?? 0))
|
||||
if (!regularRepos) return []
|
||||
const sorted = [...regularRepos].sort((a, b) => (b.lastAccessedAt ?? 0) - (a.lastAccessedAt ?? 0))
|
||||
if (!searchQuery.trim()) return sorted
|
||||
const query = searchQuery.toLowerCase()
|
||||
return sorted.filter((repo) =>
|
||||
getRepoDisplayName(repo.repoUrl, repo.localPath, repo.sourcePath).toLowerCase().includes(query)
|
||||
)
|
||||
}, [repos, searchQuery])
|
||||
}, [regularRepos, searchQuery])
|
||||
|
||||
const isUrlControlledSheet = searchParams.get('mobileTab') === 'repos'
|
||||
|
||||
@@ -57,18 +59,6 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
}
|
||||
|
||||
const handleClick = (id: number) => {
|
||||
const pendingAction = searchParams.get('mobileTabAction')
|
||||
|
||||
if (isAssistantRoute) {
|
||||
navigateAndClose(`/repos/${id}`, { replace: true })
|
||||
return
|
||||
}
|
||||
|
||||
if (pendingAction === 'assistant') {
|
||||
navigateAndClose(getAssistantPath())
|
||||
return
|
||||
}
|
||||
|
||||
if (id === activeRepoId) {
|
||||
onClose()
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user