@@ -15,14 +15,24 @@ import {
15
15
} from "@/components/ui/carousel" ;
16
16
import { RepoIndexingStatus } from "@sourcebot/db" ;
17
17
import { SymbolIcon } from "@radix-ui/react-icons" ;
18
+ import { RepositoryQuery } from "@/lib/types" ;
18
19
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 ) {
20
29
const domain = useDomain ( ) ;
21
30
22
31
const { data : repos , isPending, isError } = useQuery ( {
23
32
queryKey : [ 'repos' , domain ] ,
24
33
queryFn : ( ) => unwrapServiceError ( getRepos ( domain ) ) ,
25
34
refetchInterval : env . NEXT_PUBLIC_POLLING_INTERVAL_MS ,
35
+ placeholderData : initialRepos ,
26
36
} ) ;
27
37
28
38
if ( isPending || isError || ! repos ) {
@@ -33,22 +43,30 @@ export function RepositorySnapshot({ authEnabled }: { authEnabled: boolean }) {
33
43
)
34
44
}
35
45
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
+ }
49
68
}
50
69
51
- const indexedRepos = repos . filter ( ( repo ) => repo . repoIndexingStatus === RepoIndexingStatus . INDEXED ) ;
52
70
return (
53
71
< div className = "flex flex-col items-center gap-3" >
54
72
< span className = "text-sm" >
@@ -57,7 +75,7 @@ export function RepositorySnapshot({ authEnabled }: { authEnabled: boolean }) {
57
75
href = { `${ domain } /repos` }
58
76
className = "text-blue-500"
59
77
>
60
- { repos . length > 1 ? 'repositories' : 'repository' }
78
+ { indexedRepos . length > 1 ? 'repositories' : 'repository' }
61
79
</ Link >
62
80
</ span >
63
81
< RepositoryCarousel repos = { indexedRepos } />
0 commit comments