Navigation buttons {min,max}_id and prev

FossilOrigin-Name: c53c85a60a5d86bd2a0817b06956a64f80dc518b5fe5162495317ed332c9bc27
This commit is contained in:
me@ow.nekobit.net 2022-03-29 14:11:10 +00:00
parent d41f1e404a
commit 8676269f20
7 changed files with 62 additions and 16 deletions

17
dist/treebird20.css vendored
View file

@ -185,6 +185,23 @@ input[type=button]:active, input[type=submit]:active, .sidebarbtn:active, .btn:a
cursor: pointer;
}
.btn-disabled
{
color: #cacaca !important;
background: #f3f3f3 !important;
}
.btn-disabled:hover
{
background: #f3f3f3;
}
.btn-disabled:active
{
background: #f3f3f3;
}
input[type=button], input[type=submit]
{
border: 1px solid #cacaca;

View file

@ -16,19 +16,31 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "navigation.h"
#include "easprintf.h"
// Pages
#include "../static/navigation.chtml"
char* construct_navigation_box(char* prev_id, char* next_id, size_t* size)
#define SUBMIT_HTML "<input type=\"submit\" class=\"hidden\">"
char* construct_navigation_box(char* start_id,
char* prev_id,
char* next_id,
size_t* size)
{
char* nav_html;
int is_start = strcmp(start_id, prev_id) == 0;
size_t s = easprintf(&nav_html, data_navigation_html,
start_id,
prev_id,
// Disable button if at start
is_start ? "btn-disabled" : "",
is_start ? "" : SUBMIT_HTML,
// If user pressed next, reserve start state
start_id,
next_id);
if (size) *size = s;
return nav_html;

View file

@ -21,6 +21,9 @@
#include <stddef.h>
#include <mastodont.h>
char* construct_navigation_box(char* prev_id, char* next_id, size_t* size);
char* construct_navigation_box(char* start_id,
char* prev_id,
char* next_id,
size_t* size);
#endif // NAVIGATION_H

View file

@ -35,7 +35,6 @@ char* read_query_data()
// BEGIN Query references
struct key_value_refs refs[] = {
{ "offset", &(query.offset) },
{ "id", &(query.id) },
};
// END Query references
@ -81,6 +80,10 @@ char* read_post_data()
{ "username", &(post.username) },
{ "password", &(post.password) },
{ "replyid", &(post.replyid) },
{ "min_id", &(post.min_id) },
{ "max_id", &(post.max_id) },
{ "start_id", &(post.start_id) },
};
// END Query references

View file

@ -36,12 +36,14 @@ struct query_values
char* username;
char* password;
char* replyid;
char* min_id;
char* max_id;
char* start_id;
};
struct get_values
{
char* offset;
char* id;
};
extern struct query_values post;

View file

@ -25,6 +25,7 @@
#include "easprintf.h"
#include "reply.h"
#include "navigation.h"
#include "query.h"
#include "../static/navigation.chtml"
@ -36,14 +37,15 @@ void tl_public(mastodont_t* api, int local)
struct mstdnt_storage storage = { 0 };
char* status_format, *post_box, *navigation_box;
char* output = NULL;
char* start_id;
struct mstdnt_args args = {
.local = local,
.remote = 0,
.only_media = 0,
.max_id = NULL,
.max_id = post.max_id,
.since_id = NULL,
.min_id = NULL,
.min_id = post.min_id,
.limit = 20
};
@ -61,10 +63,15 @@ void tl_public(mastodont_t* api, int local)
cleanup = 1;
}
// If not set, set it
start_id = post.start_id ? post.start_id : statuses[0].id;
// Create post box
post_box = construct_post_box(NULL, "", NULL);
navigation_box = construct_navigation_box(
statuses[0].id, statuses[status_count].id, NULL);
navigation_box = construct_navigation_box(start_id,
statuses[0].id,
statuses[status_count-1].id,
NULL);
easprintf(&output, "%s%s%s", post_box, status_format, navigation_box);
struct base_page b = {

View file

@ -1,7 +1,7 @@
<table class="navigation ui-table">
<tr>
<td class="nav-up btn">
<form action="." method="get">
<form action="." method="post">
<label class="pointer">
<span class="nav-btn">Up</span>
<input type="submit" class="hidden">
@ -9,18 +9,20 @@
</form>
</td>
<td class="nav-prev btn">
<form action="." method="get">
<form action="." method="post">
<label class="pointer">
<input type="hidden" name="max_id" value="%s">
<span class="nav-btn">Previous</span>
<input type="submit" class="hidden">
<input type="hidden" name="start_id" value="%s">
<input type="hidden" name="min_id" value="%s">
<span class="nav-btn %s">Previous</span>
%s
</label>
</form>
</td>
<td class="nav-next btn">
<form action="." method="get">
<form action="." method="post">
<label class="pointer">
<input type="hidden" name="min_id" value="%s">
<input type="hidden" name="start_id" value="%s">
<input type="hidden" name="max_id" value="%s">
<span class="nav-btn">Next</span>
<input type="submit" class="hidden">
</label>