-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathrepositoryCarousel.tsx
More file actions
127 lines (117 loc) · 3.9 KB
/
repositoryCarousel.tsx
File metadata and controls
127 lines (117 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
'use client';
import {
Carousel,
CarouselContent,
CarouselItem,
} from "@/components/ui/carousel";
import { RepositoryQuery } from "@/lib/types";
import { getCodeHostInfoForRepo } from "@/lib/utils";
import clsx from "clsx";
import Autoscroll from "embla-carousel-auto-scroll";
import Image from "next/image";
import Link from "next/link";
import { useDomain } from "@/hooks/useDomain";
interface RepositoryCarouselProps {
displayRepos: RepositoryQuery[];
numberOfReposWithIndex: number;
}
export function RepositoryCarousel({
displayRepos,
numberOfReposWithIndex,
}: RepositoryCarouselProps) {
const domain = useDomain();
if (numberOfReposWithIndex === 0) {
return (
<div className="flex flex-col items-center gap-3">
<span className="text-sm">No repositories found</span>
<div className="w-full max-w-lg">
<div className="flex flex-row items-center gap-2 border rounded-md p-4 justify-center">
<span className="text-sm text-muted-foreground">
<>
Create a{" "}
<Link href={`/${domain}/settings/connections`} className="text-blue-500 hover:underline inline-flex items-center gap-1">
connection
</Link>{" "}
to start indexing repositories
</>
</span>
</div>
</div>
</div>
)
}
return (
<div className="flex flex-col items-center gap-3">
<span className="text-sm">
{`${numberOfReposWithIndex} `}
<Link
href={`/${domain}/repos`}
className="text-link hover:underline"
>
{numberOfReposWithIndex > 1 ? 'repositories' : 'repository'}
</Link>
{` indexed`}
</span>
<Carousel
opts={{
align: "start",
loop: true,
}}
className="w-full max-w-lg"
plugins={[
Autoscroll({
startDelay: 0,
speed: 1,
stopOnMouseEnter: true,
stopOnInteraction: false,
}),
]}
>
<CarouselContent>
{displayRepos.map((repo, index) => (
<CarouselItem key={index} className="basis-auto">
<RepositoryBadge
key={index}
repo={repo}
/>
</CarouselItem>
))}
</CarouselContent>
</Carousel>
</div>
)
}
interface RepositoryBadgeProps {
repo: RepositoryQuery;
}
const RepositoryBadge = ({
repo
}: RepositoryBadgeProps) => {
const { repoIcon, displayName } = (() => {
const info = getCodeHostInfoForRepo({
codeHostType: repo.codeHostType,
name: repo.repoName,
displayName: repo.repoDisplayName,
externalWebUrl: repo.externalWebUrl,
});
return {
repoIcon: <Image
src={info.icon}
alt={info.codeHostName}
className={`w-4 h-4 ${info.iconClassName}`}
/>,
displayName: info.displayName,
}
})();
return (
<Link
href={repo.webUrl}
className={clsx("flex flex-row items-center gap-2 border rounded-md p-2 text-clip")}
>
{repoIcon}
<span className="text-sm font-mono">
{displayName}
</span>
</Link>
)
}