|
9 | 9 | Text, |
10 | 10 | Link, |
11 | 11 | SearchBox, |
| 12 | + Tag, |
12 | 13 | TeachingPopover, |
13 | 14 | TeachingPopoverBody, |
14 | 15 | TeachingPopoverHeader, |
@@ -95,16 +96,44 @@ const SearchPage = () => { |
95 | 96 | } |
96 | 97 | }; |
97 | 98 |
|
98 | | - const handleSearchClick = (event) => { |
| 99 | + const handleSearchClick = () => { |
| 100 | + console.log('Search button clicked'); |
99 | 101 | handleSearch(); |
100 | 102 | } |
101 | 103 |
|
102 | | - const handleGoToGithub = (even) => { |
| 104 | + const handleOpenLink = (event, result) => { |
| 105 | + window.open(result.url, '_blank', 'noopener,noreferrer'); |
| 106 | + } |
| 107 | + |
| 108 | + const handleGoToGithub = () => { |
103 | 109 | window.open("https://github.com/yorek/azure-sql-db-ai-samples-search", '_blank', 'noopener,noreferrer'); |
104 | 110 | } |
105 | 111 |
|
| 112 | + const getResponseStatusFromResult = (result) => { |
| 113 | + let responseStatus = { code: 0, description: '' }; |
| 114 | + if (result.error) { |
| 115 | + console.log(error); |
| 116 | + if (result.response) { |
| 117 | + responseStatus = JSON.parse(result.response).response.status.http; |
| 118 | + if (responseStatus.code === 429) { |
| 119 | + responseStatus.description = "Too many requests. Please try again later."; |
| 120 | + } |
| 121 | + } else { |
| 122 | + responseStatus = { code: error.error_code, description: error_message }; |
| 123 | + } |
| 124 | + } |
| 125 | + return responseStatus; |
| 126 | + } |
| 127 | + |
| 128 | + let pageStatus = "first_load"; |
| 129 | + if (results.length === 0 && !loading && searchCompleted) pageStatus = "no_results"; |
| 130 | + if (results.length > 0) pageStatus = "results_found"; |
| 131 | + //console.log('Page Status:', pageStatus); |
| 132 | + //console.log('Search Completed:', searchCompleted); |
| 133 | + |
106 | 134 | return ( |
107 | 135 | <div className={styles.appContainer}> |
| 136 | + |
108 | 137 | <div className={styles.header}> |
109 | 138 | <div className={styles.title}> |
110 | 139 | Azure SQL DB Samples AI Search 💡🔍 |
@@ -141,6 +170,7 @@ const SearchPage = () => { |
141 | 170 | <Button onClick={handleGoToGithub} target="_blank">Go to GitHub Repo</Button> |
142 | 171 | </div> |
143 | 172 | </div> |
| 173 | + |
144 | 174 | <div className={styles.searchWrapper}> |
145 | 175 | <SearchBox |
146 | 176 | placeholder="Type your query in natural language. The AI will do the rest..." |
@@ -173,31 +203,27 @@ const SearchPage = () => { |
173 | 203 | </Text> |
174 | 204 | )} |
175 | 205 |
|
| 206 | + {(pageStatus === "first_load") && |
| 207 | + ( |
| 208 | + <Text block style={{ textAlign: 'center' }}> |
| 209 | + Start searching to get results! |
| 210 | + </Text> |
| 211 | + ) |
| 212 | + } |
| 213 | + |
| 214 | + {(pageStatus === "no_results") && |
| 215 | + ( |
| 216 | + <Text block style={{ textAlign: 'center' }}> |
| 217 | + No results found. Please try another query. |
| 218 | + </Text> |
| 219 | + ) |
| 220 | + } |
| 221 | + |
176 | 222 | <div className={styles.results}> |
177 | | - {results.length === 0 && !loading ? ( |
178 | | - query && searchCompleted == true ? ( |
179 | | - <Text block style={{ textAlign: 'center' }}> |
180 | | - No results found. Try a different query! |
181 | | - </Text> |
182 | | - ) : ( |
183 | | - <Text block style={{ textAlign: 'center' }}> |
184 | | - Start searching to get results! |
185 | | - </Text> |
186 | | - ) |
187 | | - ) : ( |
| 223 | + { |
188 | 224 | results.map((result, index) => { |
189 | | - let responseStatus; |
190 | | - if (result.error) { |
191 | | - console.log(error); |
192 | | - if (result.response) { |
193 | | - responseStatus = JSON.parse(result.response).response.status.http; |
194 | | - if (responseStatus.code === 429) { |
195 | | - responseStatus.description = "Too many requests. Please try again later."; |
196 | | - } |
197 | | - } else { |
198 | | - responseStatus = { code: error.error_code, description: error_message }; |
199 | | - } |
200 | | - } |
| 225 | + let responseStatus=getResponseStatusFromResult(result); |
| 226 | + |
201 | 227 | return ( |
202 | 228 | <Card key={index} className={styles.resultCard}> |
203 | 229 | {result.error ? ( |
@@ -226,17 +252,15 @@ const SearchPage = () => { |
226 | 252 | </div> |
227 | 253 | } |
228 | 254 | /> |
229 | | - <CardFooter> |
230 | | - <Link href={result.url} target="_blank" rel="noopener noreferrer"> |
231 | | - {result.url} |
232 | | - </Link> |
| 255 | + <CardFooter className={styles.resultCardFooter}> |
| 256 | + <Button onClick={(event) => handleOpenLink(event, result)}>Open Link</Button> |
233 | 257 | </CardFooter> |
234 | 258 | </> |
235 | 259 | )} |
236 | 260 | </Card> |
237 | 261 | ); |
238 | 262 | }) |
239 | | - )} |
| 263 | + } |
240 | 264 | </div> |
241 | 265 | </div> |
242 | 266 | ); |
|
0 commit comments