@@ -15,14 +15,24 @@ import {
1515} from "@/components/ui/carousel" ;
1616import { RepoIndexingStatus } from "@sourcebot/db" ;
1717import { SymbolIcon } from "@radix-ui/react-icons" ;
18+ import { RepositoryQuery } from "@/lib/types" ;
1819
19- export function RepositorySnapshot ( { authEnabled } : { authEnabled : boolean } ) {
20+ interface RepositorySnapshotProps {
21+ authEnabled : boolean ;
22+ repos : RepositoryQuery [ ] ;
23+ }
24+
25+ export function RepositorySnapshot ( {
26+ authEnabled,
27+ repos : initialRepos ,
28+ } : RepositorySnapshotProps ) {
2029 const domain = useDomain ( ) ;
2130
2231 const { data : repos , isPending, isError } = useQuery ( {
2332 queryKey : [ 'repos' , domain ] ,
2433 queryFn : ( ) => unwrapServiceError ( getRepos ( domain ) ) ,
2534 refetchInterval : env . NEXT_PUBLIC_POLLING_INTERVAL_MS ,
35+ placeholderData : initialRepos ,
2636 } ) ;
2737
2838 if ( isPending || isError || ! repos ) {
@@ -33,22 +43,30 @@ export function RepositorySnapshot({ authEnabled }: { authEnabled: boolean }) {
3343 )
3444 }
3545
36- const numIndexedRepos = repos . filter ( ( repo ) => repo . repoIndexingStatus === RepoIndexingStatus . INDEXED ) . length ;
37- const numIndexingRepos = repos . filter ( ( repo ) => repo . repoIndexingStatus === RepoIndexingStatus . INDEXING || repo . repoIndexingStatus === RepoIndexingStatus . IN_INDEX_QUEUE ) . length ;
38- if ( numIndexedRepos === 0 && numIndexingRepos > 0 ) {
39- return (
40- < div className = "flex flex-row items-center gap-3" >
41- < SymbolIcon className = "h-4 w-4 animate-spin" />
42- < span className = "text-sm" > indexing in progress...</ span >
43- </ div >
44- )
45- } else if ( numIndexedRepos == 0 ) {
46- return (
47- < EmptyRepoState domain = { domain } authEnabled = { authEnabled } />
48- )
46+ // Use `indexedAt` to determine if a repo has __ever__ been indexed.
47+ // The repo indexing status only tells us the repo's current indexing status.
48+ const indexedRepos = repos . filter ( ( repo ) => repo . indexedAt !== undefined ) ;
49+
50+ // If there are no indexed repos...
51+ if ( indexedRepos . length === 0 ) {
52+
53+ // ... show a loading state if repos are being indexed now
54+ if ( repos . some ( ( repo ) => repo . repoIndexingStatus === RepoIndexingStatus . INDEXING || repo . repoIndexingStatus === RepoIndexingStatus . IN_INDEX_QUEUE ) ) {
55+ return (
56+ < div className = "flex flex-row items-center gap-3" >
57+ < SymbolIcon className = "h-4 w-4 animate-spin" />
58+ < span className = "text-sm" > indexing in progress...</ span >
59+ </ div >
60+ )
61+
62+ // ... otherwise, show the empty state.
63+ } else {
64+ return (
65+ < EmptyRepoState domain = { domain } authEnabled = { authEnabled } />
66+ )
67+ }
4968 }
5069
51- const indexedRepos = repos . filter ( ( repo ) => repo . repoIndexingStatus === RepoIndexingStatus . INDEXED ) ;
5270 return (
5371 < div className = "flex flex-col items-center gap-3" >
5472 < span className = "text-sm" >
@@ -57,7 +75,7 @@ export function RepositorySnapshot({ authEnabled }: { authEnabled: boolean }) {
5775 href = { `${ domain } /repos` }
5876 className = "text-blue-500"
5977 >
60- { repos . length > 1 ? 'repositories' : 'repository' }
78+ { indexedRepos . length > 1 ? 'repositories' : 'repository' }
6179 </ Link >
6280 </ span >
6381 < RepositoryCarousel repos = { indexedRepos } />
0 commit comments