-2
src/static/js/search.js
-2
src/static/js/search.js
+37
-5
src/templates/search.html
+37
-5
src/templates/search.html
···
12
12
13
13
<br>
14
14
15
+
<div id="pages">
16
+
</div>
17
+
15
18
<div id="results">
16
19
</div>
17
20
18
21
<script>
19
-
const query = document.getElementById("query")
20
-
const results = document.getElementById("results")
22
+
const params = new URLSearchParams(window.location.search)
23
+
24
+
const pages = document.getElementById('pages')
25
+
const results = document.getElementById('results')
26
+
27
+
const query = document.getElementById('query')
28
+
if (query.value == '' && params.get('q')) {
29
+
query.value = params.get('q')
30
+
}
21
31
22
-
document.getElementById("search").addEventListener("click", async () => {
32
+
let offset = params.get('offset')
33
+
if (!offset) {
34
+
offset = 0
35
+
}
36
+
37
+
document.getElementById('search').addEventListener('click', async () => {
23
38
results.innerHTML = '' // yeet the children!
24
-
const search_results = await search(query.value, 10, 0)
39
+
pages.innerHTML = '' // yeet more children!
40
+
41
+
const search_results = await search(query.value, 10, Number(offset.value))
25
42
if (search_results.length >= 0) {
26
43
for (result of search_results) {
27
44
// same as components/post_mini.html except js
···
46
63
element.appendChild(p)
47
64
results.appendChild(element)
48
65
}
66
+
67
+
// set up pagination
68
+
if (offset > 0) {
69
+
const back_link = document.createElement('a')
70
+
// we escape the $ here because otherwise V will try to perform replacements at compile-time.
71
+
//todo: report this, this behaviour should be changed or at least looked into further.
72
+
back_link.href = '/search?q=' + query.value + '&limit=10&offset=' + Math.min(0, offset.value - 10)
73
+
back_link.innerText = '<-'
74
+
pages.appendChild(back_link)
75
+
76
+
const next_link = document.createElement('a')
77
+
next_link.href = '/search?q=' + query.value + '&limit=10&offset=' + (offset.value + 10)
78
+
next_link.innerText = '->'
79
+
pages.appendChild(next_link)
80
+
}
49
81
} else {
50
-
results.innerText = 'No results!'
82
+
results.innerText = 'no results!'
51
83
}
52
84
})
53
85
</script>
+1
-1
src/webapp/pages.v
+1
-1
src/webapp/pages.v