@@ -33,11 +33,11 @@ export const AskSourcebotDemoCards = ({
3333
3434 const getContextIcon = ( context : DemoSearchContext , size : number = 20 ) => {
3535 const sizeClass = size === 12 ? "h-3 w-3" : "h-5 w-5" ;
36-
36+
3737 if ( context . type === "set" ) {
3838 return < LibraryBigIcon className = { cn ( sizeClass , "text-muted-foreground" ) } /> ;
3939 }
40-
40+
4141 if ( context . codeHostType ) {
4242 const codeHostIcon = getCodeHostIcon ( context . codeHostType ) ;
4343 if ( codeHostIcon ) {
@@ -52,7 +52,7 @@ export const AskSourcebotDemoCards = ({
5252 ) ;
5353 }
5454 }
55-
55+
5656 return < Code className = { cn ( sizeClass , "text-muted-foreground" ) } /> ;
5757 }
5858
@@ -63,40 +63,48 @@ export const AskSourcebotDemoCards = ({
6363 return ;
6464 }
6565
66- if ( context . type === "set" ) {
67- const searchContext = searchContexts . find ( ( item ) => item . name === context . value ) ;
68- if ( ! searchContext ) {
69- console . error ( `Search context ${ context . value } not found on handleContextClick` ) ;
70- return ;
71- }
72-
73- const isSelected = selectedItems . some (
74- ( selected ) => selected . type === 'context' && selected . value === context . value
75- ) ;
76- const newSelectedItems = isSelected
77- ? selectedItems . filter (
78- ( selected ) => ! ( selected . type === 'context' && selected . value === context . value )
79- )
80- : [ ...selectedItems , { type : 'context' , value : context . value , name : context . displayName , repoCount : searchContext . repoNames . length } as SearchContextItem ] ;
81-
82- setSelectedItems ( newSelectedItems ) ;
83- } else {
84- const repo = repos . find ( ( repo ) => repo . repoName === context . value ) ;
85- if ( ! repo ) {
86- console . error ( `Repo ${ context . value } not found on handleContextClick` ) ;
87- return ;
88- }
66+ const isDemoMode = process . env . NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT === "demo" ;
67+ const isSelected = selectedItems . some ( ( item ) => item . value === context . value ) ;
68+ if ( isSelected ) {
69+ setSelectedItems ( selectedItems . filter ( ( item ) => item . value !== context . value ) ) ;
70+ return ;
71+ }
72+
73+ const getNewSelectedItem = ( ) : ContextItem | null => {
74+ if ( context . type === "set" ) {
75+ const searchContext = searchContexts . find ( ( item ) => item . name === context . value ) ;
76+ if ( ! searchContext ) {
77+ console . error ( `Search context ${ context . value } not found on handleContextClick` ) ;
78+ return null ;
79+ }
8980
90- const isSelected = selectedItems . some (
91- ( selected ) => selected . type === 'repo' && selected . value === context . value
92- ) ;
93- const newSelectedItems = isSelected
94- ? selectedItems . filter (
95- ( selected ) => ! ( selected . type === 'repo' && selected . value === context . value )
96- )
97- : [ ...selectedItems , { type : 'repo' , value : context . value , name : context . displayName , codeHostType : repo . codeHostType } as RepoContextItem ] ;
81+ return {
82+ type : 'context' ,
83+ value : context . value ,
84+ name : context . displayName ,
85+ repoCount : searchContext . repoNames . length
86+ } as SearchContextItem ;
87+ } else {
88+ const repo = repos . find ( ( repo ) => repo . repoName === context . value ) ;
89+ if ( ! repo ) {
90+ console . error ( `Repo ${ context . value } not found on handleContextClick` ) ;
91+ return null ;
92+ }
9893
99- setSelectedItems ( newSelectedItems ) ;
94+ return {
95+ type : 'repo' ,
96+ value : context . value ,
97+ name : context . displayName ,
98+ codeHostType : repo . codeHostType
99+ } as RepoContextItem ;
100+ }
101+ }
102+
103+ const newSelectedItem = getNewSelectedItem ( ) ;
104+ if ( newSelectedItem ) {
105+ setSelectedItems ( isDemoMode ? [ newSelectedItem ] : [ ...selectedItems , newSelectedItem ] ) ;
106+ } else {
107+ console . error ( `No new selected item found on handleContextClick` ) ;
100108 }
101109 }
102110
@@ -107,7 +115,7 @@ export const AskSourcebotDemoCards = ({
107115 < div className = "text-center mb-8" >
108116 < div className = "flex items-center justify-center gap-2 mb-2" >
109117 < Layers className = "h-5 w-5 text-muted-foreground" />
110- < h3 className = "text-lg font-semibold" > Search Context </ h3 >
118+ < h3 className = "text-lg font-semibold" > Search Contexts </ h3 >
111119 </ div >
112120 < p className = "text-sm text-muted-foreground" > Select the context you want to ask questions about</ p >
113121 </ div >
@@ -177,33 +185,34 @@ export const AskSourcebotDemoCards = ({
177185 { demoExamples . searchExamples . map ( ( example ) => {
178186 const searchContexts = demoExamples . searchContexts . filter ( ( context ) => example . searchContext . includes ( context . id ) )
179187 return (
180- < Card
181- key = { example . url }
182- className = "cursor-pointer transition-all duration-200 hover:shadow-md hover:scale-105 hover:border-primary/50 group w-full max-w-[350px]"
183- onClick = { ( ) => handleExampleClick ( example ) }
184- >
185- < CardContent className = "p-4" >
186- < div className = "space-y-3" >
187- < div className = "flex items-center justify-between" >
188- { searchContexts . map ( ( context ) => (
189- < Badge key = { context . value } variant = "secondary" className = "text-[10px] px-1.5 py-0.5 h-4 flex items-center gap-1" >
190- { getContextIcon ( context , 12 ) }
191- { context . displayName }
192- </ Badge >
193- ) ) }
194- </ div >
195- < div className = "space-y-1" >
196- < h4 className = "font-semibold text-sm group-hover:text-primary transition-colors line-clamp-2" >
197- { example . title }
198- </ h4 >
199- < p className = "text-xs text-muted-foreground line-clamp-3 leading-relaxed" >
200- { example . description }
201- </ p >
188+ < Card
189+ key = { example . url }
190+ className = "cursor-pointer transition-all duration-200 hover:shadow-md hover:scale-105 hover:border-primary/50 group w-full max-w-[350px]"
191+ onClick = { ( ) => handleExampleClick ( example ) }
192+ >
193+ < CardContent className = "p-4" >
194+ < div className = "space-y-3" >
195+ < div className = "flex items-center justify-between" >
196+ { searchContexts . map ( ( context ) => (
197+ < Badge key = { context . value } variant = "secondary" className = "text-[10px] px-1.5 py-0.5 h-4 flex items-center gap-1" >
198+ { getContextIcon ( context , 12 ) }
199+ { context . displayName }
200+ </ Badge >
201+ ) ) }
202+ </ div >
203+ < div className = "space-y-1" >
204+ < h4 className = "font-semibold text-sm group-hover:text-primary transition-colors line-clamp-2" >
205+ { example . title }
206+ </ h4 >
207+ < p className = "text-xs text-muted-foreground line-clamp-3 leading-relaxed" >
208+ { example . description }
209+ </ p >
210+ </ div >
202211 </ div >
203- </ div >
204- </ CardContent >
205- </ Card >
206- ) } ) }
212+ </ CardContent >
213+ </ Card >
214+ )
215+ } ) }
207216 </ div >
208217 </ div >
209218 </ div >
0 commit comments