From 7f654b7f5c4580e3440602995f2ac120a7ed441d Mon Sep 17 00:00:00 2001 From: nekobit Date: Sat, 2 Jul 2022 06:12:04 +0000 Subject: [PATCH] Thread pagination FossilOrigin-Name: ea762ff1808965e992f2a7685e13f06030629dfdfd014ae6fbdf9134de973e70 --- dist/treebird20.css | 27 +++++++++++++++++++++++ src/status.c | 43 ++++++++++++++++++++++++++++++++----- static/thread_page_btn.tmpl | 16 ++++++++++++++ 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 static/thread_page_btn.tmpl diff --git a/dist/treebird20.css b/dist/treebird20.css index 22ebf25..4018230 100644 --- a/dist/treebird20.css +++ b/dist/treebird20.css @@ -1704,6 +1704,11 @@ input[type=checkbox].hidden:not(:checked) + .list-edit-content box-shadow: 0px 1px 0px #dadada; } +.navigation a.btn +{ + display: block; +} + .navigation .nav-btn, .tabs .tab-btn { @@ -1711,6 +1716,28 @@ input[type=checkbox].hidden:not(:checked) + .list-edit-content padding: 6px; } +.nav-symbol +{ + color: #505050; + margin-right: 7px; +} + +.navigation .nav-symbol +{ + position: relative; + top: -2px; +} + +.thread-nav-td +{ + width: 42%; +} + +/* .thread-nav-stub */ +/* { */ +/* width: 10%; */ +/* } */ + .tabs .tab-btn { width: 100%; diff --git a/src/status.c b/src/status.c index f12b4eb..217825a 100644 --- a/src/status.c +++ b/src/status.c @@ -58,6 +58,7 @@ #include "../static/repeat_btn_img.ctmpl" #include "../static/reply_btn_img.ctmpl" #include "../static/expand_btn_img.ctmpl" +#include "../static/thread_page_btn.ctmpl" #define ACCOUNT_INTERACTIONS_LIMIT 11 #define NUM_STR "%u" @@ -984,7 +985,13 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, uint8_t *statuses_after = NULL, status = { 0 }; size_t stat_before_len = 0, stat_after_len = 0; - char* before_html = NULL, *stat_html = NULL, *after_html = NULL, *stat_reply = NULL; + char* before_html = NULL, *stat_html = NULL, *after_html = NULL, *stat_reply = NULL, + * thread_pagination = NULL; + + int stat_after_limit = 15; + int stat_before_limit = 15; +#define enough_statuses_before (stat_before_len > stat_before_limit) +#define enough_statuses_after (stat_after_len > stat_after_limit) try_post_status(ssn, api); mastodont_get_status_context(api, @@ -1000,7 +1007,12 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, uint8_t stat_html = construct_error("Status not found", E_ERROR, 1, NULL); } else { - before_html = construct_statuses(ssn, api, statuses_before, stat_before_len, NULL, 0); + before_html = construct_statuses(ssn, api, + (enough_statuses_before ? + statuses_before + (stat_before_len - stat_before_limit) : statuses_before), + (enough_statuses_before ? + stat_before_limit : stat_before_len), + NULL, 0); // Current status stat_html = construct_status(ssn, api, &status, NULL, NULL, NULL, flags); @@ -1013,13 +1025,33 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, uint8_t } // After... - after_html = construct_statuses(ssn, api, statuses_after, stat_after_len, NULL, 0); + // For pagination, we already start at the first, so no math required here + after_html = construct_statuses(ssn, api, statuses_after, + (enough_statuses_after ? stat_after_limit : stat_after_len), + NULL, 0); - easprintf(&output, "%s%s%s%s", + // Thread pagination buttons + if (statuses_before || statuses_after) + { + struct thread_page_btn_template pagination_tmpl = { + .prefix = config_url_prefix, + .status_first = (statuses_before ? statuses_before[0].id : "deadbeef"), + .status_last = (statuses_after ? statuses_after[stat_after_len-1].id : "deadbeef"), + .status_before = (statuses_before && enough_statuses_before ? statuses_before[stat_before_len - stat_before_limit].id : "deadbeef"), + .status_after = (statuses_after && enough_statuses_after ? + statuses_after[stat_after_limit].id : "deadbeef"), + }; + thread_pagination = tmpl_gen_thread_page_btn(&pagination_tmpl, NULL); + } + + + easprintf(&output, "%s%s%s%s%s%s", + thread_pagination ? thread_pagination : "", before_html ? before_html : "", stat_html ? stat_html : "", stat_reply ? stat_reply : "", - after_html ? after_html : ""); + after_html ? after_html : "", + thread_pagination ? thread_pagination : ""); struct base_page b = { .category = BASE_CAT_NONE, @@ -1035,6 +1067,7 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, uint8_t free(stat_html); free(after_html); free(output); + free(thread_pagination); if ((flags & STATUS_REPLY) == STATUS_REPLY) free(stat_reply); mstdnt_cleanup_statuses(statuses_before, stat_before_len); diff --git a/static/thread_page_btn.tmpl b/static/thread_page_btn.tmpl new file mode 100644 index 0000000..479f871 --- /dev/null +++ b/static/thread_page_btn.tmpl @@ -0,0 +1,16 @@ + + + + + + + +