Skip to content

Commit 2325a95

Browse files
committed
better ux
1 parent 6be19eb commit 2325a95

File tree

2 files changed

+68
-50
lines changed

2 files changed

+68
-50
lines changed

client/src/SearchPage.jsx

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Text,
1010
Link,
1111
SearchBox,
12+
Tag,
1213
TeachingPopover,
1314
TeachingPopoverBody,
1415
TeachingPopoverHeader,
@@ -95,16 +96,44 @@ const SearchPage = () => {
9596
}
9697
};
9798

98-
const handleSearchClick = (event) => {
99+
const handleSearchClick = () => {
100+
console.log('Search button clicked');
99101
handleSearch();
100102
}
101103

102-
const handleGoToGithub = (even) => {
104+
const handleOpenLink = (event, result) => {
105+
window.open(result.url, '_blank', 'noopener,noreferrer');
106+
}
107+
108+
const handleGoToGithub = () => {
103109
window.open("https://github.com/yorek/azure-sql-db-ai-samples-search", '_blank', 'noopener,noreferrer');
104110
}
105111

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+
106134
return (
107135
<div className={styles.appContainer}>
136+
108137
<div className={styles.header}>
109138
<div className={styles.title}>
110139
Azure SQL DB Samples AI Search 💡🔍
@@ -141,6 +170,7 @@ const SearchPage = () => {
141170
<Button onClick={handleGoToGithub} target="_blank">Go to GitHub Repo</Button>
142171
</div>
143172
</div>
173+
144174
<div className={styles.searchWrapper}>
145175
<SearchBox
146176
placeholder="Type your query in natural language. The AI will do the rest..."
@@ -173,31 +203,27 @@ const SearchPage = () => {
173203
</Text>
174204
)}
175205

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+
176222
<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+
{
188224
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+
201227
return (
202228
<Card key={index} className={styles.resultCard}>
203229
{result.error ? (
@@ -226,17 +252,15 @@ const SearchPage = () => {
226252
</div>
227253
}
228254
/>
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>
233257
</CardFooter>
234258
</>
235259
)}
236260
</Card>
237261
);
238262
})
239-
)}
263+
}
240264
</div>
241265
</div>
242266
);

client/src/assets/styles/SearchPage.module.css

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.appContainer {
22
padding: 20px;
3-
font-family: 'Open Sans', sans-serif;
4-
font-size: x-large;
3+
font-family: 'Open Sans', sans-serif;
54
}
65

76
.header {
@@ -40,7 +39,6 @@
4039

4140
.searchBox input {
4241
padding: 10px;
43-
height: 40px;
4442
}
4543

4644
.searchButton {
@@ -61,19 +59,23 @@
6159
}
6260

6361
.results {
64-
font-size: medium;
62+
font-size: small;
6563
width: 75%; /* Add this line to set the width to 75% */
6664
margin: 40px auto; /* Center the results */
65+
display: grid;
66+
grid-template-columns: auto auto auto;
67+
justify-content: center;
68+
margin-bottom: 20px;
69+
gap: 10px;
6770
}
6871

6972
.resultCardHeader {
7073
font-size: large;
71-
font-weight: bold;
72-
margin-bottom: 10px;
74+
font-weight: bold;
7375
}
7476

7577
.resultCard {
76-
margin-bottom: 20px;
78+
width: 400px;
7779
}
7880

7981
.resultDescription {
@@ -85,16 +87,8 @@
8587
color: #555555;
8688
}
8789

88-
.nav {
89-
margin-top: 10px;
90-
}
91-
92-
.navLink {
93-
margin-right: 15px;
94-
text-decoration: none;
95-
font-weight: bold;
96-
}
97-
98-
.navLink:hover {
99-
text-decoration: underline;
100-
}
90+
.resultCardFooter {
91+
margin-left: auto;
92+
margin-right: auto;
93+
margin-top: auto;
94+
}

0 commit comments

Comments
 (0)