From eb71b8c1ba948225951a994e8aac29029d85a6f5 Mon Sep 17 00:00:00 2001 From: blankie Date: Sun, 9 Apr 2023 15:29:47 +0700 Subject: [PATCH] Focus page selector when going through pages --- routes/users/illustrations.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/routes/users/illustrations.cpp b/routes/users/illustrations.cpp index 9c19a68..47233c1 100644 --- a/routes/users/illustrations.cpp +++ b/routes/users/illustrations.cpp @@ -6,7 +6,7 @@ #include "../../pixivclient.h" #include "common.h" -static Element generate_pager(const Illusts& illusts, size_t page); +static Element generate_pager(const Illusts& illusts, size_t page, bool first_selector); static inline Element generate_content(const httplib::Request& req, const Config& config, const Illusts& illusts); void user_illustrations_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client) { @@ -35,19 +35,21 @@ void user_illustrations_route(const httplib::Request& req, httplib::Response& re Element body("body", { generate_user_header(std::move(user), config), - generate_pager(illusts, page), + generate_pager(illusts, page, true), Element("br"), generate_content(req, config, illusts), - generate_pager(illusts, page) + generate_pager(illusts, page, false) }); serve(req, res, config, user.display_name + " illustrations", std::move(body)); } -static Element generate_pager(const Illusts& illusts, size_t page) { - using namespace std::string_literals; +static Element generate_pager(const Illusts& illusts, size_t page, bool first_selector) { + auto link = [](size_t new_page, const char* text, bool add_link) { + using namespace std::string_literals; - auto link = [](std::string href, const char* text, bool add_link) { Element b("b"); + std::string href = "?p="s + std::to_string(new_page) + "#pageselector"; + if (add_link) { b.nodes.push_back(Element("a", {{"href", std::move(href)}}, {text})); } else { @@ -55,13 +57,18 @@ static Element generate_pager(const Illusts& illusts, size_t page) { } return b; }; - return Element("div", {{"class", "center"}}, { - link("?p=1", "First", page != 0), " ", - link("?p="s + std::to_string(page), "Prev", page != 0), " ", + + Element div("div", {{"class", "center"}}, { + link(1, "First", page != 0), " ", + link(page, "Prev", page != 0), " ", std::to_string(page + 1), "/", std::to_string(illusts.total_pages), " ", - link("?p="s + std::to_string(page + 2), "Next", page + 1 < illusts.total_pages), " ", - link("?p="s + std::to_string(illusts.total_pages), "Last", page + 1 < illusts.total_pages) + link(page + 2, "Next", page + 1 < illusts.total_pages), " ", + link(illusts.total_pages, "Last", page + 1 < illusts.total_pages) }); + if (first_selector) { + div.attributes.push_back({"id", "pageselector"}); + } + return div; } static inline Element generate_content(const httplib::Request& req, const Config& config, const Illusts& illusts) {