Properly link to the different sections of a profile
This commit is contained in:
parent
6510af79ff
commit
2ee5bc537b
|
@ -7,9 +7,9 @@ static const char* sorting_method_names[3] = {"Posts", "Posts and replies", "Med
|
||||||
static const char* sorting_method_suffixes[3] = {"", "/with_replies", "/media"};
|
static const char* sorting_method_suffixes[3] = {"", "/with_replies", "/media"};
|
||||||
static inline PostSortingMethod get_sorting_method(const std::string& method);
|
static inline PostSortingMethod get_sorting_method(const std::string& method);
|
||||||
|
|
||||||
static inline Element user_header(const Account& account, PostSortingMethod sorting_method);
|
static inline Element user_header(const httplib::Request& req, const Account& account, PostSortingMethod sorting_method);
|
||||||
static inline Element user_link_field(const AccountField& field);
|
static inline Element user_link_field(const AccountField& field);
|
||||||
static inline Element sorting_method_link(const Account& account, PostSortingMethod current_method, PostSortingMethod new_method);
|
static inline Element sorting_method_link(const httplib::Request& req, const Account& account, PostSortingMethod current_method, PostSortingMethod new_method);
|
||||||
|
|
||||||
|
|
||||||
void user_route(const httplib::Request& req, httplib::Response& res) {
|
void user_route(const httplib::Request& req, httplib::Response& res) {
|
||||||
|
@ -33,7 +33,7 @@ void user_route(const httplib::Request& req, httplib::Response& res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Element body("body", {
|
Element body("body", {
|
||||||
user_header(*account, sorting_method),
|
user_header(req, *account, sorting_method),
|
||||||
});
|
});
|
||||||
serve(req, res, account->display_name + " (" + account->username + '@' + account->domain_name + ')', std::move(body));
|
serve(req, res, account->display_name + " (" + account->username + '@' + account->domain_name + ')', std::move(body));
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ static inline PostSortingMethod get_sorting_method(const std::string& method) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline Element user_header(const Account& account, PostSortingMethod sorting_method) {
|
static inline Element user_header(const httplib::Request& req, const Account& account, PostSortingMethod sorting_method) {
|
||||||
struct tm created_at;
|
struct tm created_at;
|
||||||
char created_at_str[16];
|
char created_at_str[16];
|
||||||
gmtime_r(&account.created_at, &created_at);
|
gmtime_r(&account.created_at, &created_at);
|
||||||
|
@ -88,9 +88,9 @@ static inline Element user_header(const Account& account, PostSortingMethod sort
|
||||||
}),
|
}),
|
||||||
|
|
||||||
Element("nav", {{"class", "user_page-user_posts_nav"}}, {
|
Element("nav", {{"class", "user_page-user_posts_nav"}}, {
|
||||||
sorting_method_link(account, sorting_method, PostSortingMethod::Posts),
|
sorting_method_link(req, account, sorting_method, PostSortingMethod::Posts),
|
||||||
sorting_method_link(account, sorting_method, PostSortingMethod::PostsAndReplies),
|
sorting_method_link(req, account, sorting_method, PostSortingMethod::PostsAndReplies),
|
||||||
sorting_method_link(account, sorting_method, PostSortingMethod::Media),
|
sorting_method_link(req, account, sorting_method, PostSortingMethod::Media),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
return header;
|
return header;
|
||||||
|
@ -115,14 +115,13 @@ static inline Element user_link_field(const AccountField& field) {
|
||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Element sorting_method_link(const Account& account, PostSortingMethod current_method, PostSortingMethod new_method) {
|
static inline Element sorting_method_link(const httplib::Request& req, const Account& account, PostSortingMethod current_method, PostSortingMethod new_method) {
|
||||||
using namespace std::string_literals;
|
|
||||||
const char* method_name = sorting_method_names[new_method];
|
const char* method_name = sorting_method_names[new_method];
|
||||||
|
|
||||||
if (current_method == new_method) {
|
if (current_method == new_method) {
|
||||||
return Element("b", {method_name});
|
return Element("b", {method_name});
|
||||||
} else {
|
} else {
|
||||||
return Element("a", {{"href", "/"s + account.domain_name + "/@" + account.username + sorting_method_suffixes[new_method]}}, {
|
return Element("a", {{"href", get_origin(req) + '/' + account.domain_name + "/@" + account.username + sorting_method_suffixes[new_method]}}, {
|
||||||
method_name,
|
method_name,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue