From c7eeb0aa3c97248b8d12b664a52c0e3a5b7c5e47 Mon Sep 17 00:00:00 2001 From: th3r00t Date: Wed, 6 Aug 2025 00:24:23 +0000 Subject: [PATCH] Finished Pagination --- src/backend/lib/storage.py | 6 ++-- src/frontend/lib/FastAPIServer.py | 13 ++++++++- src/frontend/static/styles/pyShelf.sass | 37 +++++++++++++++++++++++++ src/frontend/templates/collection.html | 17 ++++++++---- src/frontend/templates/footer.html | 32 ++++++++++----------- src/frontend/templates/index.html | 17 ++++++++---- src/frontend/templates/navigation.html | 4 +++ 7 files changed, 95 insertions(+), 31 deletions(-) diff --git a/src/backend/lib/storage.py b/src/backend/lib/storage.py index 6823b69..63daad0 100644 --- a/src/backend/lib/storage.py +++ b/src/backend/lib/storage.py @@ -251,13 +251,15 @@ class Storage: .join(BookCollection) .where(BookCollection.collection_id == collection) .offset(skip or 0) - .limit(limit or 100) + # .limit(limit or 100) + .limit(limit) ).scalars().all() else: result = session.execute( select(Book) .offset(skip or 0) - .limit(limit or 100) + # .limit(limit or 100) + .limit(limit) ).scalars().all() return result diff --git a/src/frontend/lib/FastAPIServer.py b/src/frontend/lib/FastAPIServer.py index ff405eb..6e29b38 100644 --- a/src/frontend/lib/FastAPIServer.py +++ b/src/frontend/lib/FastAPIServer.py @@ -3,6 +3,7 @@ import uvicorn import os import sass import datetime +import math # import gzip # import brotli from json import dumps @@ -176,7 +177,15 @@ class FastAPIServer(): books = storage.get_books(collection=None, skip=skip_num, limit=limit) collections = storage.get_collections() """Home page responder.""" - context = {"request": request, "books": books, "collections": collections, "page": skip, "limit": limit} + total_books = len(storage.get_books()) + context = { + "request": request, + "total_pages": math.ceil(total_books / limit), + "books": books, + "collections": collections, + "page": skip, + "limit": limit + } return templates.TemplateResponse("index.html", context) @app.get("/api/books", response_class=JSONResponse) @@ -222,12 +231,14 @@ class FastAPIServer(): else: skip_num = skip * limit books = storage.get_books(collection, skip=skip_num, limit=limit) + total_books = len(storage.get_books(collection)) collections = storage.get_collections() context = { "request": request, "books": books, "collections": collections, "collection": collection, + "total_pages": math.ceil(total_books / limit), "page": skip, "limit": limit } diff --git a/src/frontend/static/styles/pyShelf.sass b/src/frontend/static/styles/pyShelf.sass index 644c7f0..c5ed4a2 100644 --- a/src/frontend/static/styles/pyShelf.sass +++ b/src/frontend/static/styles/pyShelf.sass @@ -108,8 +108,45 @@ $footer-background-color: $ps-color-primary-trans !important align-content: center; background-color: $ps-color-background; +#collection_dropdown + margin-top: auto; + margin-bottom: auto; + .footer display: flex; padding: 1rem !important; + +#pagination-container + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-between; + width: 100%; + padding: 0.5rem; + +#pagination-left, #pagination-right + background-color: $ps-color-secondary; + +#pagination-left + display: flex; + justify-content: flex-start; + +#pagination-center + display: flex; + justify-content: center; + flex: 1; + +#pagination-right + display: flex; + justify-content: flex-end; + @import "../../node_modules/bulma/bulma.scss" + +.container-full + width: 100%; + height: 100%; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; diff --git a/src/frontend/templates/collection.html b/src/frontend/templates/collection.html index 3efb811..05eb68e 100644 --- a/src/frontend/templates/collection.html +++ b/src/frontend/templates/collection.html @@ -27,7 +27,7 @@
-