Focus page selector when going through pages
This commit is contained in:
parent
fef9a2f36e
commit
eb71b8c1ba
|
@ -6,7 +6,7 @@
|
||||||
#include "../../pixivclient.h"
|
#include "../../pixivclient.h"
|
||||||
#include "common.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);
|
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) {
|
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", {
|
Element body("body", {
|
||||||
generate_user_header(std::move(user), config),
|
generate_user_header(std::move(user), config),
|
||||||
generate_pager(illusts, page),
|
generate_pager(illusts, page, true),
|
||||||
Element("br"),
|
Element("br"),
|
||||||
generate_content(req, config, illusts),
|
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));
|
serve(req, res, config, user.display_name + " illustrations", std::move(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Element generate_pager(const Illusts& illusts, size_t page) {
|
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;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
auto link = [](std::string href, const char* text, bool add_link) {
|
|
||||||
Element b("b");
|
Element b("b");
|
||||||
|
std::string href = "?p="s + std::to_string(new_page) + "#pageselector";
|
||||||
|
|
||||||
if (add_link) {
|
if (add_link) {
|
||||||
b.nodes.push_back(Element("a", {{"href", std::move(href)}}, {text}));
|
b.nodes.push_back(Element("a", {{"href", std::move(href)}}, {text}));
|
||||||
} else {
|
} else {
|
||||||
|
@ -55,13 +57,18 @@ static Element generate_pager(const Illusts& illusts, size_t page) {
|
||||||
}
|
}
|
||||||
return b;
|
return b;
|
||||||
};
|
};
|
||||||
return Element("div", {{"class", "center"}}, {
|
|
||||||
link("?p=1", "First", page != 0), " ",
|
Element div("div", {{"class", "center"}}, {
|
||||||
link("?p="s + std::to_string(page), "Prev", page != 0), " ",
|
link(1, "First", page != 0), " ",
|
||||||
|
link(page, "Prev", page != 0), " ",
|
||||||
std::to_string(page + 1), "/", std::to_string(illusts.total_pages), " ",
|
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(page + 2, "Next", page + 1 < illusts.total_pages), " ",
|
||||||
link("?p="s + std::to_string(illusts.total_pages), "Last", 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) {
|
static inline Element generate_content(const httplib::Request& req, const Config& config, const Illusts& illusts) {
|
||||||
|
|
Loading…
Reference in New Issue