0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-25 07:28:22 -05:00

Merge pull request #2 from neon-mmd/pagination-support-search-page

add previous and next button to navigate to different pages
This commit is contained in:
neon_arch 2023-05-03 18:36:54 +00:00 committed by GitHub
commit 31f17855ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 13 deletions

View File

@ -0,0 +1,26 @@
function navigate_forward() {
const url = new URL(window.location)
const searchParams = url.searchParams
let q = searchParams.get('q')
let page = searchParams.get('page')
if (page === null) {
page = 2
window.location = `${url.origin}${url.pathname}?q=${q}&page=${page}`
} else {
window.location = `${url.origin}${url.pathname}?q=${q}&page=${++page}`
}
}
function navigate_backward() {
const url = new URL(window.location)
const searchParams = url.searchParams
let q = searchParams.get('q')
let page = searchParams.get('page')
if (page !== null && page > 1) {
window.location = `${url.origin}${url.pathname}?q=${q}&page=${--page}`
}
}

View File

@ -240,3 +240,23 @@ footer {
.error_content p a:hover { .error_content p a:hover {
color: var(--5); color: var(--5);
} }
.page_navigation {
padding: 0 0 2rem 0;
display: flex;
justify-content: space-between;
align-items: center;
}
.page_navigation button {
background: var(--bg);
color: var(--fg);
padding: 1rem;
border-radius: 0.5rem;
outline: none;
border: none;
}
.page_navigation button:active {
filter: brightness(1.2);
}

View File

@ -1,20 +1,25 @@
{{>header this.style}} {{>header this.style}}
<main class="results"> <main class="results">
{{>search_bar}} {{>search_bar}}
<div class="results_aggregated"> <div class="results_aggregated">
{{#each results}} {{#each results}}
<div class="result"> <div class="result">
<h1><a href="{{this.visitingUrl}}">{{{this.title}}}</a></h1> <h1><a href="{{this.visitingUrl}}">{{{this.title}}}</a></h1>
<small>{{this.url}}</small> <small>{{this.url}}</small>
<p>{{{this.description}}}</p> <p>{{{this.description}}}</p>
<div class="upstream_engines"> <div class="upstream_engines">
{{#each engine}} {{#each engine}}
<span>{{this}}</span> <span>{{this}}</span>
{{/each}}
</div>
</div>
{{/each}} {{/each}}
</div>
</div> </div>
{{/each}}
</div>
<div class="page_navigation">
<button type="button" onclick="navigate_backward()">&#8592; previous</button>
<button type="button" onclick="navigate_forward()">next &#8594;</button>
</div>
</main> </main>
<script src="static/index.js"></script> <script src="static/index.js"></script>
<script src="static/pagination.js"></script>
{{>footer}} {{>footer}}