|
1 | 1 | import gleam/bool |
2 | 2 | import gleam/dict |
3 | 3 | import gleam/dynamic/decode |
| 4 | +import gleam/int |
4 | 5 | import gleam/list |
5 | 6 | import gleam/option.{None, Some} |
6 | 7 | import gleam/string |
7 | 8 | import hexdocs/components/iframe |
| 9 | +import hexdocs/config |
8 | 10 | import hexdocs/data/model.{type Model} |
9 | 11 | import hexdocs/data/model/autocomplete |
10 | 12 | import hexdocs/data/msg |
@@ -247,8 +249,8 @@ pub fn search(model: Model) { |
247 | 249 | ]), |
248 | 250 | ], |
249 | 251 | ), |
250 | | - html.div([class("flex-1 md:ml-0 mt-0 md:mt-0")], [ |
251 | | - html.div([class("p-5 flex flex-col items-center")], [ |
| 252 | + html.div([class("px-5 my-5 flex-1")], [ |
| 253 | + html.div([class("flex flex-col items-center")], [ |
252 | 254 | html.div([class("w-full max-w-[800px] flex items-center gap-3")], [ |
253 | 255 | html.div([class("relative flex-1")], [ |
254 | 256 | html.input([ |
@@ -296,13 +298,52 @@ pub fn search(model: Model) { |
296 | 298 | ), |
297 | 299 | ]), |
298 | 300 | ]), |
299 | | - html.div([class("px-5 flex flex-col items-center")], [ |
300 | | - html.div([class("space-y-6 w-full max-w-[800px]")], { |
301 | | - let results = option.unwrap(model.search_result, #(0, [])) |
302 | | - use result <- list.map(results.1) |
303 | | - result_card(model, result) |
304 | | - }), |
305 | | - ]), |
| 301 | + html.div([class("flex flex-col mx-auto max-w-[800px]")], { |
| 302 | + case string.is_empty(model.search_input) { |
| 303 | + True -> [] |
| 304 | + False -> { |
| 305 | + let #(count, results) = |
| 306 | + option.unwrap(model.search_result, #(0, [])) |
| 307 | + [ |
| 308 | + html.div( |
| 309 | + [ |
| 310 | + class("py-4 text-slate-700 dark:text-slate-300"), |
| 311 | + class("flex flex-row justify-between"), |
| 312 | + ], |
| 313 | + [ |
| 314 | + html.div([], [ |
| 315 | + case count <= config.per_page() { |
| 316 | + True -> "Found " |
| 317 | + False -> |
| 318 | + "Showing first " |
| 319 | + |> string.append(int.to_string(config.per_page())) |
| 320 | + |> string.append(" out of ") |
| 321 | + } |
| 322 | + |> string.append(int.to_string(count)) |
| 323 | + |> string.append(" results") |
| 324 | + |> html.text(), |
| 325 | + ]), |
| 326 | + html.div([class("text-sm")], [ |
| 327 | + html.text("Search powered by "), |
| 328 | + html.a( |
| 329 | + [ |
| 330 | + class("text-blue-600"), |
| 331 | + attribute.href("https://typesense.org"), |
| 332 | + ], |
| 333 | + [ |
| 334 | + html.text("TypeSense"), |
| 335 | + ], |
| 336 | + ), |
| 337 | + ]), |
| 338 | + ], |
| 339 | + ), |
| 340 | + html.div([class("space-y-6")], { |
| 341 | + list.map(results, result_card(model, _)) |
| 342 | + }), |
| 343 | + ] |
| 344 | + } |
| 345 | + } |
| 346 | + }), |
306 | 347 | ]), |
307 | 348 | ]), |
308 | 349 | ]) |
|
0 commit comments