@@ -5,9 +5,10 @@ import { Button } from "@/components/ui/button";
5
5
import { Tooltip , TooltipContent , TooltipTrigger } from "@/components/ui/tooltip" ;
6
6
import { CustomEditor , LanguageModelInfo , MentionElement , RenderElementPropsFor , SearchScope } from "@/features/chat/types" ;
7
7
import { insertMention , slateContentToString } from "@/features/chat/utils" ;
8
+ import { SearchContextQuery } from "@/lib/types" ;
8
9
import { cn , IS_MAC } from "@/lib/utils" ;
9
10
import { computePosition , flip , offset , shift , VirtualElement } from "@floating-ui/react" ;
10
- import { ArrowUp , Loader2 , StopCircleIcon , TriangleAlertIcon } from "lucide-react" ;
11
+ import { ArrowUp , Loader2 , StopCircleIcon } from "lucide-react" ;
11
12
import { Fragment , KeyboardEvent , useCallback , useEffect , useMemo , useRef , useState } from "react" ;
12
13
import { useHotkeys } from "react-hotkeys-hook" ;
13
14
import { Descendant , insertText } from "slate" ;
@@ -17,8 +18,6 @@ import { SuggestionBox } from "./suggestionsBox";
17
18
import { Suggestion } from "./types" ;
18
19
import { useSuggestionModeAndQuery } from "./useSuggestionModeAndQuery" ;
19
20
import { useSuggestionsData } from "./useSuggestionsData" ;
20
- import { useToast } from "@/components/hooks/use-toast" ;
21
- import { SearchContextQuery } from "@/lib/types" ;
22
21
23
22
interface ChatBoxProps {
24
23
onSubmit : ( children : Descendant [ ] , editor : CustomEditor ) => void ;
@@ -30,7 +29,6 @@ interface ChatBoxProps {
30
29
languageModels : LanguageModelInfo [ ] ;
31
30
selectedSearchScopes : SearchScope [ ] ;
32
31
searchContexts : SearchContextQuery [ ] ;
33
- onContextSelectorOpenChanged : ( isOpen : boolean ) => void ;
34
32
}
35
33
36
34
export const ChatBox = ( {
@@ -43,7 +41,6 @@ export const ChatBox = ({
43
41
languageModels,
44
42
selectedSearchScopes,
45
43
searchContexts,
46
- onContextSelectorOpenChanged,
47
44
} : ChatBoxProps ) => {
48
45
const suggestionsBoxRef = useRef < HTMLDivElement > ( null ) ;
49
46
const [ index , setIndex ] = useState ( 0 ) ;
@@ -70,7 +67,6 @@ export const ChatBox = ({
70
67
const { selectedLanguageModel } = useSelectedLanguageModel ( {
71
68
initialLanguageModel : languageModels . length > 0 ? languageModels [ 0 ] : undefined ,
72
69
} ) ;
73
- const { toast } = useToast ( ) ;
74
70
75
71
// Reset the index when the suggestion mode changes.
76
72
useEffect ( ( ) => {
@@ -101,9 +97,9 @@ export const ChatBox = ({
101
97
return < Leaf { ...props } />
102
98
} , [ ] ) ;
103
99
104
- const { isSubmitDisabled, isSubmitDisabledReason } = useMemo ( ( ) : {
100
+ const { isSubmitDisabled } = useMemo ( ( ) : {
105
101
isSubmitDisabled : true ,
106
- isSubmitDisabledReason : "empty" | "redirecting" | "generating" | "no-repos-selected" | "no- language-model-selected"
102
+ isSubmitDisabledReason : "empty" | "redirecting" | "generating" | "no-language-model-selected"
107
103
} | {
108
104
isSubmitDisabled : false ,
109
105
isSubmitDisabledReason : undefined ,
@@ -129,13 +125,6 @@ export const ChatBox = ({
129
125
}
130
126
}
131
127
132
- if ( selectedSearchScopes . length === 0 ) {
133
- return {
134
- isSubmitDisabled : true ,
135
- isSubmitDisabledReason : "no-repos-selected" ,
136
- }
137
- }
138
-
139
128
if ( selectedLanguageModel === undefined ) {
140
129
141
130
return {
@@ -149,29 +138,11 @@ export const ChatBox = ({
149
138
isSubmitDisabledReason : undefined ,
150
139
}
151
140
152
- } , [
153
- editor . children ,
154
- isRedirecting ,
155
- isGenerating ,
156
- selectedSearchScopes . length ,
157
- selectedLanguageModel ,
158
- ] )
141
+ } , [ editor . children , isRedirecting , isGenerating , selectedLanguageModel ] )
159
142
160
143
const onSubmit = useCallback ( ( ) => {
161
- if ( isSubmitDisabled ) {
162
- if ( isSubmitDisabledReason === "no-repos-selected" ) {
163
- toast ( {
164
- description : "⚠️ You must select at least one search scope" ,
165
- variant : "destructive" ,
166
- } ) ;
167
- onContextSelectorOpenChanged ( true ) ;
168
- }
169
-
170
- return ;
171
- }
172
-
173
144
_onSubmit ( editor . children , editor ) ;
174
- } , [ _onSubmit , editor , isSubmitDisabled , isSubmitDisabledReason , toast , onContextSelectorOpenChanged ] ) ;
145
+ } , [ _onSubmit , editor ] ) ;
175
146
176
147
const onInsertSuggestion = useCallback ( ( suggestion : Suggestion ) => {
177
148
switch ( suggestion . type ) {
@@ -310,39 +281,15 @@ export const ChatBox = ({
310
281
Stop
311
282
</ Button >
312
283
) : (
313
- < Tooltip >
314
- < TooltipTrigger asChild >
315
- < div
316
- onClick = { ( ) => {
317
- // @hack : When submission is disabled, we still want to issue
318
- // a warning to the user as to why the submission is disabled.
319
- // onSubmit on the Button will not be called because of the
320
- // disabled prop, hence the call here.
321
- if ( isSubmitDisabled ) {
322
- onSubmit ( ) ;
323
- }
324
- } }
325
- >
326
- < Button
327
- variant = { isSubmitDisabled ? "outline" : "default" }
328
- size = "sm"
329
- className = "w-6 h-6"
330
- onClick = { onSubmit }
331
- disabled = { isSubmitDisabled }
332
- >
333
- < ArrowUp className = "w-4 h-4" />
334
- </ Button >
335
- </ div >
336
- </ TooltipTrigger >
337
- { ( isSubmitDisabled && isSubmitDisabledReason === "no-repos-selected" ) && (
338
- < TooltipContent >
339
- < div className = "flex flex-row items-center" >
340
- < TriangleAlertIcon className = "h-4 w-4 text-warning mr-1" />
341
- < span className = "text-destructive" > You must select at least one search scope</ span >
342
- </ div >
343
- </ TooltipContent >
344
- ) }
345
- </ Tooltip >
284
+ < Button
285
+ variant = { isSubmitDisabled ? "outline" : "default" }
286
+ size = "sm"
287
+ className = "w-6 h-6"
288
+ onClick = { onSubmit }
289
+ disabled = { isSubmitDisabled }
290
+ >
291
+ < ArrowUp className = "w-4 h-4" />
292
+ </ Button >
346
293
) }
347
294
</ div >
348
295
{ suggestionMode !== "none" && (
0 commit comments