Search page pagination w/out JS

FossilOrigin-Name: e40f45e2d41593d47060e5a7daa0aadadc95ea3e55965f1bc7fa026f06e53251
This commit is contained in:
nekobit 2022-06-18 06:23:43 +00:00
parent ffa4d9cabb
commit a129f9178f
5 changed files with 123 additions and 9 deletions

8
dist/treebird20.css vendored
View file

@ -56,11 +56,17 @@ ul
border-radius: 5px;
}
.hidden
.hidden,
.search-page-hidden + .search-page
{
display: none;
}
.search-page-hidden:checked + .search-page
{
display: block;
}
.pointer
{
cursor: pointer;

View file

@ -89,7 +89,7 @@ int main(void)
{ "/search/statuses", content_search_statuses },
{ "/search/accounts", content_search_accounts },
{ "/search/hashtags", content_search_hashtags },
{ "/search", content_search_statuses },
{ "/search", content_search_all },
{ "/lists/for/:", content_tl_list },
{ "/lists", content_lists },
{ "/federated", content_tl_federated },

View file

@ -30,6 +30,7 @@
// Pages
#include "../static/search.ctmpl"
#include "../static/search_all.ctmpl"
void search_page(struct session* ssn, mastodont_t* api, enum search_tab tab, char* content)
{
@ -55,7 +56,98 @@ void search_page(struct session* ssn, mastodont_t* api, enum search_tab tab, cha
// Output
render_base_page(&b, ssn, api);
free(out_data);
free(out_data);
}
void content_search_all(struct session* ssn, mastodont_t* api, char** data)
{
char* out_data = NULL;
char* statuses_html = NULL;
char* accounts_html = NULL;
char* tags_html = NULL,
* tags_graph = NULL,
* tags_bars = NULL,
* tags_page = NULL;
struct mstdnt_storage storage = { 0 };
struct mstdnt_search_args args = {
.account_id = NULL,
.type = 0,
.resolve = 0,
.following = 0,
.with_relationships = 0,
.max_id = NULL,
.min_id = NULL,
.since_id = NULL,
.offset = 0,
.limit = 20,
};
struct mstdnt_search_results results = { 0 };
if (mastodont_search(api,
keystr(ssn->query.query),
&storage,
&args,
&results) == 0)
{
// Statuses, make sure to set the highlight word
struct construct_statuses_args statuses_args = {
.highlight_word = keystr(ssn->query.query),
};
statuses_html = construct_statuses(ssn, api, results.statuses, results.statuses_len, &statuses_args, NULL);
if (!statuses_html)
statuses_html = construct_error("No statuses", E_ERROR, 1, NULL);
// Accounts
accounts_html = construct_accounts(api, results.accts, results.accts_len, 0, NULL);
if (!accounts_html)
accounts_html = construct_error("No accounts", E_ERROR, 1, NULL);
// Hashtags
tags_html = construct_hashtags(results.tags, results.tags_len, NULL);
if (!tags_html)
tags_html = construct_error("No hashtags", E_ERROR, 1, NULL);
tags_bars = construct_hashtags_graph(results.tags,
results.tags_len,
14,
NULL);
if (tags_bars)
tags_graph = construct_bar_graph_container(tags_bars, NULL);
free(tags_bars);
}
easprintf(&tags_page, "%s%s", STR_NULL_EMPTY(tags_graph), tags_html);
// Construct search page
struct search_all_template tdata = {
.accounts = "Accounts",
.hashtags = "Hashtags",
.statuses = "Statuses",
.statuses_results = statuses_html,
.hashtags_results = tags_page,
.accounts_results = accounts_html
};
out_data = tmpl_gen_search_all(&tdata, NULL);
struct base_page b = {
.category = BASE_CAT_NONE,
.content = out_data,
.sidebar_left = NULL
};
// Output
render_base_page(&b, ssn, api);
free(out_data);
free(statuses_html);
free(accounts_html);
free(tags_html);
free(tags_graph);
free(tags_page);
mstdnt_cleanup_search_results(&results);
mastodont_storage_cleanup(&storage);
}
void content_search_statuses(struct session* ssn, mastodont_t* api, char** data)

View file

@ -29,7 +29,7 @@ enum search_tab
};
void search_page(struct session* ssn, mastodont_t* api, enum search_tab tab, char* content);
void content_search_all(struct session* ssn, mastodont_t* api, char** data);
void content_search_statuses(struct session* ssn, mastodont_t* api, char** data);
void content_search_accounts(struct session* ssn, mastodont_t* api, char** data);
void content_search_hashtags(struct session* ssn, mastodont_t* api, char** data);

View file

@ -1,18 +1,34 @@
<table class="tabs ui-table">
<tr>
<td>
<label for
<a href="{{%s:prefix}}/search/statuses?q={{%s:query}}"><input class="tab-btn btn {{%s:statuses_active}}" type="button" value="{{%s:statuses}}"></a>
<label for="statuses-results-hidden">
<span class="tab-btn btn">{{%s:statuses}}</span>
</label>
</td>
<td>
<a href="{{%s:prefix}}/search/accounts?q={{%s:query}}"><input class="tab-btn btn {{%s:accounts_active}}" type="button" value="{{%s:accounts}}"></a>
<label for="accounts-results-hidden">
<span class="tab-btn btn">{{%s:accounts}}</span>
</label>
</td>
<td>
<a href="{{%s:prefix}}/search/hashtags?q={{%s:query}}"><input class="tab-btn btn {{%s:hashtags_active}}" type="button" value="{{%s:hashtags}}"></a>
<label for="hashtags-results-hidden">
<span class="tab-btn btn">{{%s:hashtags}}</span>
</label>
</td>
</tr>
</table>
<div class="search-results">
{{%s:results}}
<input type="radio" class="search-page-hidden hidden" id="statuses-results-hidden" name="searchpage" checked>
<div class="statuses-results search-page">
{{%s:statuses_results}}
</div>
<input type="radio" class="search-page-hidden hidden" id="accounts-results-hidden" name="searchpage">
<div class="accounts-results search-page">
{{%s:accounts_results}}
</div>
<input type="radio" class="search-page-hidden hidden" id="hashtags-results-hidden" name="searchpage">
<div class="hashtags-results search-page">
{{%s:hashtags_results}}
</div>
</div>