-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.tsx
105 lines (99 loc) · 2.95 KB
/
page.tsx
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
"use client";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Skeleton } from "@/components/ui/skeleton";
import { GitHubLogoIcon } from "@radix-ui/react-icons";
import { useCompletion } from "ai/react";
import { useEffect, useState } from "react";
import Markdown from "react-markdown";
export default function Page() {
const {
input,
handleInputChange,
setInput,
handleSubmit,
error,
completion,
isLoading,
} = useCompletion({
api: "/generate",
});
const [sampleRepoUrl, setSampleRepoUrl] = useState<string | null>(null);
useEffect(() => {
if (!sampleRepoUrl) return;
handleSubmit();
setSampleRepoUrl(null);
}, [sampleRepoUrl, handleSubmit]);
const onClickSampleRepo = (url: string) => {
setInput(url);
setSampleRepoUrl(url);
};
return (
<div className="flex flex-col gap-8 mb-8">
<form
className="flex flex-col sm:flex-row gap-2 relative"
onSubmit={handleSubmit}
>
<div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-4">
<GitHubLogoIcon className="size-5 text-stone-400" />
</div>
<Input
type="url"
name="url"
value={input}
onChange={handleInputChange}
required
disabled={isLoading}
placeholder="Enter public GitHub repository URL"
className="text-lg rounded-full px-4 pl-12 h-12 transition-all bg-stone-900"
/>
<Button
size="lg"
type="submit"
disabled={isLoading}
className="h-12 rounded-full text-lg font-medium bg-slate-200 transition-colors"
>
Submit
</Button>
</form>
{isLoading && completion.trim() === "" ? (
<div className="space-y-2">
<Skeleton className="h-12 w-[550px]" />
<Skeleton className="h-12 w-[500px]" />
<Skeleton className="h-12 w-[520px]" />
<Skeleton className="h-12 w-[480px]" />
</div>
) : error ? (
<div className="bg-rose-950 px-4 rounded-md py-2 text-base text-rose-200">
{error.message}
</div>
) : completion ? (
<div className="text-base prose prose-stone prose-sm prose-invert">
<Markdown>{completion}</Markdown>
</div>
) : (
<div className="flex flex-wrap gap-2">
<SampleRepo slug="microsoft/typescript" onClick={onClickSampleRepo} />
<SampleRepo slug="facebook/react" onClick={onClickSampleRepo} />
<SampleRepo slug="vercel/next.js" onClick={onClickSampleRepo} />
</div>
)}
</div>
);
}
const SampleRepo = ({
slug,
onClick,
}: {
slug: string;
onClick: (url: string) => void;
}) => (
<Button
variant="outline"
className="text-stone-300 gap-2"
onClick={() => onClick(`https://github.com/${slug}`)}
>
{slug}
<span className="text-stone-500">{"->"}</span>
</Button>
);