refactor: persist assistant repo in database with ID migration (#271)

This commit is contained in:
Chris Scott authored and GitHub committed 2026-06-09 14:46:39 -04:00
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
+10 -4
View File
@@ -24,6 +24,7 @@ import {
type RepoSortMode,
} from "./repo-list-state"
import { RepoListControls } from "./RepoListControls"
import { ASSISTANT_REPO_ID } from "@opencode-manager/shared/utils"
function formatActivityLabel(timestamp: number): string {
const now = Date.now()
@@ -175,6 +176,11 @@ export function RepoList() {
queryFn: listRepos,
})
const regularRepos = useMemo(
() => repos?.filter((r) => r.id !== ASSISTANT_REPO_ID) ?? null,
[repos],
)
const repoForDelete = useMemo(() => {
return repoToDelete ? repos?.find(r => r.id === repoToDelete) : null
}, [repoToDelete, repos])
@@ -188,7 +194,7 @@ export function RepoList() {
}
}, [selectedRepos, repos])
const repoIds = repos?.map((repo) => repo.id) || []
const repoIds = regularRepos?.map((repo) => repo.id) || []
const { data: gitStatuses } = useQuery({
queryKey: ["reposGitStatus", repoIds],
@@ -199,9 +205,9 @@ export function RepoList() {
})
const viewModels = useMemo(() => {
if (!repos) return []
return buildRepoViewModels(repos, gitStatuses)
}, [repos, gitStatuses])
if (!regularRepos) return []
return buildRepoViewModels(regularRepos, gitStatuses)
}, [regularRepos, gitStatuses])
const filteredViewModels = useMemo(() => {
const searched = filterReposBySearch(viewModels, searchQuery)