|
1 |
| -"use client"; |
| 1 | +import Home from "@/components/home"; |
2 | 2 |
|
3 |
| -import { commitChange } from "@/action"; |
4 |
| -import { Button } from "@/components/ui/button"; |
5 |
| -import { Card } from "@/components/ui/card"; |
6 |
| -import { Input } from "@/components/ui/input"; |
7 |
| -import { Label } from "@/components/ui/label"; |
8 |
| -import { ScrollArea } from "@/components/ui/scroll-area"; |
9 |
| -import { toastVariants } from "@/components/ui/toast"; |
10 |
| -import { useToast } from "@/components/ui/use-toast"; |
11 |
| -import { cn } from "@/lib/utils"; |
12 |
| -import { CornerDownLeft } from "lucide-react"; |
13 |
| -import React from "react"; |
14 |
| -import dynamic from "next/dynamic"; |
15 |
| -import ListSuggestion from "@/components/listSuggestion"; |
16 |
| -import Loader from "@/components/loader"; |
17 |
| -import { Spinner } from "@/components/ui/spinner"; |
18 |
| -import { Switch } from "@/components/ui/switch"; |
19 |
| -import { |
20 |
| - Tooltip, |
21 |
| - TooltipContent, |
22 |
| - TooltipTrigger, |
23 |
| -} from "@/components/ui/tooltip"; |
24 |
| - |
25 |
| -const EmptyScreen = dynamic(() => import("@/components/emptyScreen"), { |
26 |
| - ssr: false, |
27 |
| - loading: () => <Loader />, |
28 |
| -}); |
29 |
| - |
30 |
| -export default function Home() { |
31 |
| - const [message, setMessage] = React.useState<string | null>(null); |
32 |
| - const [isLoading, setIsLoading] = React.useState(false); |
33 |
| - const [error, setError] = React.useState<string | null>(null); |
34 |
| - const [commitChanges, setcommitChanges] = React.useState<string | null>(null); |
35 |
| - const [isEmojiSupport, setIsEmojiSupport] = React.useState<boolean>(false); |
36 |
| - const [commitMessages, setcommitMessages] = React.useState<string | null>( |
37 |
| - null |
38 |
| - ); |
39 |
| - |
40 |
| - const { toast } = useToast(); |
41 |
| - |
42 |
| - const handelSubmit = async ({ |
43 |
| - suggestion, |
44 |
| - force = false, |
45 |
| - }: { |
46 |
| - suggestion: string; |
47 |
| - force?: boolean; |
48 |
| - }) => { |
49 |
| - if (!force && suggestion === commitChanges) { |
50 |
| - toast({ |
51 |
| - variant: "destructive", |
52 |
| - title: "Duplicate Message", |
53 |
| - description: "Please enter a different message.", |
54 |
| - }); |
55 |
| - return; |
56 |
| - } |
57 |
| - |
58 |
| - setIsLoading(true); |
59 |
| - setError(null); |
60 |
| - |
61 |
| - try { |
62 |
| - const { data, error } = await commitChange({ |
63 |
| - message: suggestion, |
64 |
| - isEmojiSupport: isEmojiSupport, |
65 |
| - }); |
66 |
| - |
67 |
| - if (error) { |
68 |
| - setError(error); |
69 |
| - toast({ |
70 |
| - variant: "destructive", |
71 |
| - title: "Uh oh! Something went wrong.", |
72 |
| - description: error, |
73 |
| - action: ( |
74 |
| - <button |
75 |
| - className={cn( |
76 |
| - toastVariants({ |
77 |
| - variant: "destructive", |
78 |
| - className: "w-fit m-0 p-2 text-xs hover:bg-[#815305]/35", |
79 |
| - }) |
80 |
| - )} |
81 |
| - onClick={() => handelSubmit({ suggestion })} |
82 |
| - > |
83 |
| - Try again |
84 |
| - </button> |
85 |
| - ), |
86 |
| - }); |
87 |
| - } else { |
88 |
| - if (data) { |
89 |
| - setcommitMessages(data.text); |
90 |
| - console.log(data.text); |
91 |
| - setcommitChanges(suggestion); |
92 |
| - setMessage(""); |
93 |
| - } |
94 |
| - } |
95 |
| - } catch (error) { |
96 |
| - console.log(error); |
97 |
| - } finally { |
98 |
| - setIsLoading(false); |
99 |
| - } |
100 |
| - }; |
101 |
| - |
102 |
| - const submitForm = ( |
103 |
| - e: React.FormEvent<HTMLFormElement>, |
104 |
| - message: string | null |
105 |
| - ): void => { |
106 |
| - e.preventDefault(); |
107 |
| - handelSubmit({ suggestion: message || "" }); |
108 |
| - }; |
109 |
| - |
110 |
| - return ( |
111 |
| - <div className=" h-full py-10 flex items-center justify-center"> |
112 |
| - <ScrollArea className="h-screen w-full"> |
113 |
| - <div className=" flex h-screen mx-0 lg:mx-48 xl:mx-60 flex-col p-4 lg:col-span-2"> |
114 |
| - <div className="w-full h-5/6 mb-2 flex items-end"> |
115 |
| - <Card className="h-full w-full py-4 flex justify-center items-center bg-primary-foreground/25"> |
116 |
| - <ScrollArea className=" flex justify-center items-center w-full"> |
117 |
| - {error ? ( |
118 |
| - <div className="w-full flex items-center justify-center"> |
119 |
| - <h3 className="scroll-m-20 text-2xl font-semibold tracking-tight"> |
120 |
| - Oops! Something Went Wrong!{" "} |
121 |
| - <span className="ml-2"> : ( </span> |
122 |
| - </h3> |
123 |
| - <p className="text-sm text-muted-foreground">{error}</p> |
124 |
| - </div> |
125 |
| - ) : isLoading ? ( |
126 |
| - <div className="w-full flex items-center justify-center"> |
127 |
| - <Loader /> |
128 |
| - </div> |
129 |
| - ) : commitMessages ? ( |
130 |
| - <ListSuggestion |
131 |
| - suggestions={commitMessages!} |
132 |
| - commitChanges={commitChanges || ""} |
133 |
| - submitForm={submitForm} |
134 |
| - forceSubmit={handelSubmit} |
135 |
| - /> |
136 |
| - ) : ( |
137 |
| - <div className="w-full flex items-center justify-center"> |
138 |
| - <EmptyScreen onSubmit={handelSubmit} /> |
139 |
| - </div> |
140 |
| - )} |
141 |
| - </ScrollArea> |
142 |
| - </Card> |
143 |
| - </div> |
144 |
| - |
145 |
| - <div className="flex-1" /> |
146 |
| - |
147 |
| - <form |
148 |
| - onSubmit={(e) => submitForm(e, message)} |
149 |
| - className="relative overflow-hidden rounded-lg border bg-primary-foreground/25 focus-within:ring-1 focus-within:ring-ring shadow" |
150 |
| - > |
151 |
| - <Label htmlFor="message" className="sr-only"> |
152 |
| - Message |
153 |
| - </Label> |
154 |
| - <Input |
155 |
| - id="message" |
156 |
| - placeholder="Describe your changes here..." |
157 |
| - className="min-h-12 resize-none border-0 p-3 shadow-none focus-visible:ring-0" |
158 |
| - onChange={(e) => setMessage(e.target.value)} |
159 |
| - value={message || ""} |
160 |
| - disabled={isLoading} |
161 |
| - autoComplete="off" |
162 |
| - autoFocus |
163 |
| - required |
164 |
| - /> |
165 |
| - <div className="flex items-center p-3 pt-0"> |
166 |
| - <div className="flex items-center space-x-2"> |
167 |
| - <Switch |
168 |
| - onCheckedChange={(e) => setIsEmojiSupport(e)} |
169 |
| - id="emoji-mode" |
170 |
| - /> |
171 |
| - <Label htmlFor="emoji-mode">Emoji Mode</Label> |
172 |
| - </div> |
173 |
| - <Button |
174 |
| - type="submit" |
175 |
| - size="sm" |
176 |
| - className={cn("ml-auto gap-1.5", { |
177 |
| - "bg-primary-foreground text-muted-foreground border cursor-not-allowed hover:bg-primary-foreground": |
178 |
| - !message || isLoading, |
179 |
| - })} |
180 |
| - disabled={isLoading} |
181 |
| - > |
182 |
| - {isLoading && <Spinner className="size-4" />} |
183 |
| - Generate |
184 |
| - <CornerDownLeft className="size-3.5" /> |
185 |
| - </Button> |
186 |
| - </div> |
187 |
| - </form> |
188 |
| - </div> |
189 |
| - </ScrollArea> |
190 |
| - </div> |
191 |
| - ); |
| 3 | +export default function Page() { |
| 4 | + return <Home />; |
192 | 5 | }
|
0 commit comments