neon_arch commited on
Commit
a912e64
1 Parent(s): 664fba2

add previous and next button to navigate to different pages

Browse files
public/static/pagination.js ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function navigate_forward() {
2
+ const url = new URL(window.location)
3
+ const searchParams = url.searchParams
4
+
5
+ let q = searchParams.get('q')
6
+ let page = searchParams.get('page')
7
+
8
+ if (page === null) {
9
+ page = 2
10
+ window.location = `${url.origin}${url.pathname}?q=${q}&page=${page}`
11
+ } else {
12
+ window.location = `${url.origin}${url.pathname}?q=${q}&page=${++page}`
13
+ }
14
+ }
15
+
16
+ function navigate_backward() {
17
+ const url = new URL(window.location)
18
+ const searchParams = url.searchParams
19
+
20
+ let q = searchParams.get('q')
21
+ let page = searchParams.get('page')
22
+
23
+ if (page !== null && page > 1) {
24
+ window.location = `${url.origin}${url.pathname}?q=${q}&page=${--page}`
25
+ }
26
+ }
public/static/themes/simple.css CHANGED
@@ -240,3 +240,23 @@ footer {
240
  .error_content p a:hover {
241
  color: var(--5);
242
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  .error_content p a:hover {
241
  color: var(--5);
242
  }
243
+
244
+ .page_navigation {
245
+ padding: 0 0 2rem 0;
246
+ display: flex;
247
+ justify-content: space-between;
248
+ align-items: center;
249
+ }
250
+
251
+ .page_navigation button {
252
+ background: var(--bg);
253
+ color: var(--fg);
254
+ padding: 1rem;
255
+ border-radius: 0.5rem;
256
+ outline: none;
257
+ border: none;
258
+ }
259
+
260
+ .page_navigation button:active {
261
+ filter: brightness(1.2);
262
+ }
public/templates/search.html CHANGED
@@ -1,20 +1,25 @@
1
  {{>header this.style}}
2
  <main class="results">
3
- {{>search_bar}}
4
- <div class="results_aggregated">
5
- {{#each results}}
6
- <div class="result">
7
- <h1><a href="{{this.visitingUrl}}">{{{this.title}}}</a></h1>
8
- <small>{{this.url}}</small>
9
- <p>{{{this.description}}}</p>
10
- <div class="upstream_engines">
11
- {{#each engine}}
12
- <span>{{this}}</span>
13
- {{/each}}
14
- </div>
15
- </div>
16
  {{/each}}
 
17
  </div>
 
 
 
 
 
 
18
  </main>
19
  <script src="static/index.js"></script>
 
20
  {{>footer}}
 
1
  {{>header this.style}}
2
  <main class="results">
3
+ {{>search_bar}}
4
+ <div class="results_aggregated">
5
+ {{#each results}}
6
+ <div class="result">
7
+ <h1><a href="{{this.visitingUrl}}">{{{this.title}}}</a></h1>
8
+ <small>{{this.url}}</small>
9
+ <p>{{{this.description}}}</p>
10
+ <div class="upstream_engines">
11
+ {{#each engine}}
12
+ <span>{{this}}</span>
 
 
 
13
  {{/each}}
14
+ </div>
15
  </div>
16
+ {{/each}}
17
+ </div>
18
+ <div class="page_navigation">
19
+ <button type="button" onclick="navigate_backward()">&#8592; previous</button>
20
+ <button type="button" onclick="navigate_forward()">next &#8594;</button>
21
+ </div>
22
  </main>
23
  <script src="static/index.js"></script>
24
+ <script src="static/pagination.js"></script>
25
  {{>footer}}