-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathInputForm.tsx
More file actions
183 lines (177 loc) · 6.76 KB
/
InputForm.tsx
File metadata and controls
183 lines (177 loc) · 6.76 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { SquarePen, Brain, Send, StopCircle, Zap, Cpu } from "lucide-react";
import { Textarea } from "@/components/ui/textarea";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
// Updated InputFormProps
interface InputFormProps {
onSubmit: (inputValue: string, effort: string, model: string) => void;
onCancel: () => void;
isLoading: boolean;
hasHistory: boolean;
}
export const InputForm: React.FC<InputFormProps> = ({
onSubmit,
onCancel,
isLoading,
hasHistory,
}) => {
const [internalInputValue, setInternalInputValue] = useState("");
const [effort, setEffort] = useState("medium");
const [model, setModel] = useState("gemini-2.5-flash");
const handleInternalSubmit = (e?: React.FormEvent) => {
if (e) e.preventDefault();
if (!internalInputValue.trim()) return;
onSubmit(internalInputValue, effort, model);
setInternalInputValue("");
};
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
// Submit on Enter; use Shift+Enter for a newline.
if (e.key !== "Enter") {
return;
}
if (e.shiftKey) {
return;
}
e.preventDefault();
handleInternalSubmit();
};
const isSubmitDisabled = !internalInputValue.trim() || isLoading;
return (
<form
onSubmit={handleInternalSubmit}
className={`flex flex-col gap-2 p-3 pb-4`}
>
<div
className={`flex flex-row items-center justify-between text-white rounded-3xl rounded-bl-sm ${
hasHistory ? "rounded-br-sm" : ""
} break-words min-h-7 bg-neutral-700 px-4 pt-3 `}
>
<Textarea
value={internalInputValue}
onChange={(e) => setInternalInputValue(e.target.value)}
onKeyDown={handleKeyDown}
placeholder="Who won the Euro 2024 and scored the most goals?"
className={`w-full text-neutral-100 placeholder-neutral-500 resize-none border-0 focus:outline-none focus:ring-0 outline-none focus-visible:ring-0 shadow-none
md:text-base min-h-[56px] max-h-[200px]`}
rows={1}
/>
<div className="-mt-3">
{isLoading ? (
<Button
type="button"
variant="ghost"
size="icon"
className="text-red-500 hover:text-red-400 hover:bg-red-500/10 p-2 cursor-pointer rounded-full transition-all duration-200"
onClick={onCancel}
>
<StopCircle className="h-5 w-5" />
</Button>
) : (
<Button
type="submit"
variant="ghost"
className={`${
isSubmitDisabled
? "text-neutral-500"
: "text-blue-500 hover:text-blue-400 hover:bg-blue-500/10"
} p-2 cursor-pointer rounded-full transition-all duration-200 text-base`}
disabled={isSubmitDisabled}
>
Search
<Send className="h-5 w-5" />
</Button>
)}
</div>
</div>
<div className="flex items-center justify-between">
<div className="flex flex-row gap-2">
<div className="flex flex-row gap-2 bg-neutral-700 border-neutral-600 text-neutral-300 focus:ring-neutral-500 rounded-xl rounded-t-sm pl-2 max-w-[100%] sm:max-w-[90%]">
<div className="flex flex-row items-center text-sm">
<Brain className="h-4 w-4 mr-2" />
Effort
</div>
<Select value={effort} onValueChange={setEffort}>
<SelectTrigger className="w-[120px] bg-transparent border-none cursor-pointer">
<SelectValue placeholder="Effort" />
</SelectTrigger>
<SelectContent className="bg-neutral-700 border-neutral-600 text-neutral-300 cursor-pointer">
<SelectItem
value="low"
className="hover:bg-neutral-600 focus:bg-neutral-600 cursor-pointer"
>
Low
</SelectItem>
<SelectItem
value="medium"
className="hover:bg-neutral-600 focus:bg-neutral-600 cursor-pointer"
>
Medium
</SelectItem>
<SelectItem
value="high"
className="hover:bg-neutral-600 focus:bg-neutral-600 cursor-pointer"
>
High
</SelectItem>
</SelectContent>
</Select>
</div>
<div className="flex flex-row gap-2 bg-neutral-700 border-neutral-600 text-neutral-300 focus:ring-neutral-500 rounded-xl rounded-t-sm pl-2 max-w-[100%] sm:max-w-[90%]">
<div className="flex flex-row items-center text-sm ml-2">
<Cpu className="h-4 w-4 mr-2" />
Model
</div>
<Select value={model} onValueChange={setModel}>
<SelectTrigger className="w-[150px] bg-transparent border-none cursor-pointer">
<SelectValue placeholder="Model" />
</SelectTrigger>
<SelectContent className="bg-neutral-700 border-neutral-600 text-neutral-300 cursor-pointer">
<SelectItem
value="gemini-2.0-flash"
className="hover:bg-neutral-600 focus:bg-neutral-600 cursor-pointer"
>
<div className="flex items-center">
<Zap className="h-4 w-4 mr-2 text-yellow-400" /> 2.0 Flash
</div>
</SelectItem>
<SelectItem
value="gemini-2.5-flash"
className="hover:bg-neutral-600 focus:bg-neutral-600 cursor-pointer"
>
<div className="flex items-center">
<Zap className="h-4 w-4 mr-2 text-orange-400" /> 2.5 Flash
</div>
</SelectItem>
<SelectItem
value="gemini-2.5-pro"
className="hover:bg-neutral-600 focus:bg-neutral-600 cursor-pointer"
>
<div className="flex items-center">
<Cpu className="h-4 w-4 mr-2 text-purple-400" /> 2.5 Pro
</div>
</SelectItem>
</SelectContent>
</Select>
</div>
</div>
{hasHistory && (
<Button
className="bg-neutral-700 border-neutral-600 text-neutral-300 cursor-pointer rounded-xl rounded-t-sm pl-2 "
variant="default"
onClick={() => window.location.reload()}
>
<SquarePen size={16} />
New Search
</Button>
)}
</div>
</form>
);
};