0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-22 05:58:21 -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

@ -15,6 +15,11 @@
</div> </div>
{{/each}} {{/each}}
</div> </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}}