Skip to content

Commit b280e2d

Browse files
fix: Fix repo carousel thrashing (#294)
1 parent eb10d59 commit b280e2d

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- Fixes bug with repos not being visible in the homepage carousel when re-indexing. [#294](https://github.com/sourcebot-dev/sourcebot/pull/294)
12+
1013
### Added
1114
- Added special `*` value for `rev:` to allow searching across all branches. [#281](https://github.com/sourcebot-dev/sourcebot/pull/281)
1215

packages/web/src/app/[domain]/components/repositorySnapshot.tsx

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,24 @@ import {
1515
} from "@/components/ui/carousel";
1616
import { RepoIndexingStatus } from "@sourcebot/db";
1717
import { 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} />

packages/web/src/app/[domain]/page.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ import { SourcebotLogo } from "../components/sourcebotLogo";
1010
import { RepositorySnapshot } from "./components/repositorySnapshot";
1111
import { SyntaxReferenceGuideHint } from "./components/syntaxReferenceGuideHint";
1212
import { env } from '@/env.mjs';
13+
import { getRepos } from "@/actions";
14+
import { isServiceError } from "@/lib/utils";
1315

1416
export default async function Home({ params: { domain } }: { params: { domain: string } }) {
1517
const org = await getOrgFromDomain(domain);
1618
if (!org) {
1719
return <PageNotFound />
1820
}
1921

22+
const repos = await getRepos(domain);
23+
2024
return (
2125
<div className="flex flex-col items-center overflow-hidden min-h-screen">
2226
<NavigationMenu
@@ -34,7 +38,10 @@ export default async function Home({ params: { domain } }: { params: { domain: s
3438
className="mt-4 w-full max-w-[800px]"
3539
/>
3640
<div className="mt-8">
37-
<RepositorySnapshot authEnabled={env.SOURCEBOT_AUTH_ENABLED === 'true'} />
41+
<RepositorySnapshot
42+
authEnabled={env.SOURCEBOT_AUTH_ENABLED === 'true'}
43+
repos={isServiceError(repos) ? [] : repos}
44+
/>
3845
</div>
3946
<div className="flex flex-col items-center w-fit gap-6">
4047
<Separator className="mt-5" />

0 commit comments

Comments
 (0)