Skip to content

Commit aafdc1c

Browse files
committed
Show results count
1 parent aa2fb4b commit aafdc1c

File tree

4 files changed

+59
-14
lines changed

4 files changed

+59
-14
lines changed

src/hexdocs/config.gleam

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
/// Get the search API URL
21
pub fn search_url() -> String {
32
"https://search.hexdocs.pm"
43
}
54

6-
/// Get the hexdocs base URL
75
pub fn hexdocs_url() -> String {
86
"https://hexdocs.pm"
97
}
108

11-
/// Get the hex.pm API URL
129
pub fn hexpm_url() -> String {
1310
"https://hex.pm"
1411
}
12+
13+
pub fn per_page() -> Int {
14+
20
15+
}

src/hexdocs/services/hexdocs.gleam

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import gleam/option.{type Option, None, Some}
99
import gleam/result
1010
import gleam/string
1111
import gleam/uri
12+
import hexdocs/config
1213
import hexdocs/endpoints
1314
import hexdocs/loss
1415

@@ -94,6 +95,7 @@ fn new_search_query_params(
9495
|> list.key_set("query_by", "title,doc,type")
9596
|> list.key_set("query_by_weights", "3,1,1")
9697
|> list.key_set("page", int.to_string(page))
98+
|> list.key_set("per_page", int.to_string(config.per_page()))
9799
|> add_filter_by_packages_param(packages)
98100
|> uri.query_to_string
99101
}

src/hexdocs/view/home/footer.gleam

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ pub fn footer() {
4747
),
4848
]),
4949
h.div([a.class("text-gray-600 dark:text-gray-200")], [
50-
h.a([a.href("https://typesense.org")], [
51-
h.text("Search powered by Typesense"),
50+
h.text("Search powered by "),
51+
h.a([a.class("text-blue-600"), a.href("https://typesense.org")], [
52+
h.text("Typesense"),
5253
]),
5354
]),
5455
],

src/hexdocs/view/search.gleam

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import gleam/bool
22
import gleam/dict
33
import gleam/dynamic/decode
4+
import gleam/int
45
import gleam/list
56
import gleam/option.{None, Some}
67
import gleam/string
78
import hexdocs/components/iframe
9+
import hexdocs/config
810
import hexdocs/data/model.{type Model}
911
import hexdocs/data/model/autocomplete
1012
import hexdocs/data/msg
@@ -247,8 +249,8 @@ pub fn search(model: Model) {
247249
]),
248250
],
249251
),
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")], [
252254
html.div([class("w-full max-w-[800px] flex items-center gap-3")], [
253255
html.div([class("relative flex-1")], [
254256
html.input([
@@ -296,13 +298,52 @@ pub fn search(model: Model) {
296298
),
297299
]),
298300
]),
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+
}),
306347
]),
307348
]),
308349
])

0 commit comments

Comments
 (0)