-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathgithub-repo-part.tsx
More file actions
58 lines (55 loc) · 1.75 KB
/
Copy pathgithub-repo-part.tsx
File metadata and controls
58 lines (55 loc) · 1.75 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
import { GitForkIcon, StarIcon } from "lucide-react"
import { type GithubRepoToolPart } from "@/tools"
import { safeHttpUrl } from "@/lib/utils"
import { Spinner } from "@/components/ui/spinner"
const formatCount = new Intl.NumberFormat("en", {
notation: "compact",
maximumFractionDigits: 1,
}).format
export function GithubRepoPart({ part }: { part: GithubRepoToolPart }) {
switch (part.state) {
case "input-streaming":
case "input-available":
return (
<div className="flex items-center gap-2 text-sm text-muted-foreground">
<Spinner />
Looking up {part.input?.repo ?? "repository"}…
</div>
)
case "output-available":
if ("error" in part.output) {
return (
<div className="text-sm text-destructive">{part.output.error}</div>
)
}
return (
<a
href={safeHttpUrl(part.output.url) ?? "#"}
target="_blank"
rel="noreferrer"
className="flex w-fit items-center gap-3 px-1.5 text-sm text-muted-foreground hover:text-foreground"
>
<span className="font-medium text-foreground">
{part.output.repo}
</span>
<span className="flex items-center gap-1">
<StarIcon className="size-3.5" />
{formatCount(part.output.stars)}
</span>
<span className="flex items-center gap-1">
<GitForkIcon className="size-3.5" />
{formatCount(part.output.forks)}
</span>
<span>{part.output.language}</span>
</a>
)
case "output-error":
return (
<div className="text-sm text-destructive">
Repository lookup failed: {part.errorText}
</div>
)
default:
return null
}
}