Search functions

FossilOrigin-Name: 1079a61c79c7ade533027a59b1bcc3641b50604851f13dbc82aeed9d9c044c7d
This commit is contained in:
me@ow.nekobit.net 2022-05-04 00:11:17 +00:00
parent aa08c964d6
commit 657b648938
7 changed files with 45 additions and 38 deletions

View file

@ -38,7 +38,6 @@
#include "../static/bookmarks_page.chtml"
#define FOLLOWS_YOU_HTML "<span class=\"acct-badge\">%s</span>"
#define MAKE_FOCUSED_IF(tab, test_tab) ((tab) == test_tab ? "focused" : "")
char* load_account_info(struct mstdnt_account* acct,
size_t* size)

View file

@ -85,7 +85,6 @@ int main(void)
{ "/login", content_login },
{ "/test", content_test },
{ "/user/:/action/:", content_account_action },
{ "/search", content_search },
{ "/@:/scrobbles", content_account_scrobbles },
{ "/@:/pinned", content_account_pinned },
{ "/@:/media", content_account_media },
@ -95,10 +94,10 @@ int main(void)
{ "/status/:/reply", status_reply },
{ "/status/:", status_view },
{ "/notice/:", notice_redirect },
{ "/search", content_search },
{ "/search/statuses", content_search },
{ "/search/accounts", content_search },
{ "/search/hashtags", content_search },
{ "/search/statuses", content_search_statuses },
{ "/search/accounts", content_search_accounts },
{ "/search/hashtags", content_search_hashtags },
{ "/search", content_search_statuses },
{ "/lists/for/:", content_tl_list },
{ "/lists", content_lists },
{ "/federated", content_tl_federated },

View file

@ -24,9 +24,6 @@
#include "query.h"
#include "mime.h"
struct query_values post = { 0 };
struct get_values query = { 0 };
char* read_query_data(struct get_values* query)
{
struct http_query_info info;

View file

@ -26,20 +26,23 @@
// Pages
#include "../static/search.chtml"
void content_search(struct session* ssn, mastodont_t* api, char** data)
void search_page(struct session* ssn, mastodont_t* api, enum search_tab tab, char* content)
{
char* out_data;
easprintf(&out_data, data_search_html,
config_url_prefix,
ssn->query.query,
MAKE_FOCUSED_IF(tab, SEARCH_STATUSES),
"Statuses",
config_url_prefix,
ssn->query.query,
MAKE_FOCUSED_IF(tab, SEARCH_ACCOUNTS),
"Accounts",
config_url_prefix,
ssn->query.query,
MAKE_FOCUSED_IF(tab, SEARCH_HASHTAGS),
"Hashtags",
"Nothing");
content);
struct base_page b = {
.category = BASE_CAT_NONE,
@ -51,5 +54,20 @@ void content_search(struct session* ssn, mastodont_t* api, char** data)
// Output
render_base_page(&b, ssn, api);
free(out_data);
free(out_data);
}
void content_search_statuses(struct session* ssn, mastodont_t* api, char** data)
{
search_page(ssn, api, SEARCH_STATUSES, "statuses");
}
void content_search_accounts(struct session* ssn, mastodont_t* api, char** data)
{
search_page(ssn, api, SEARCH_ACCOUNTS, "accounts");
}
void content_search_hashtags(struct session* ssn, mastodont_t* api, char** data)
{
search_page(ssn, api, SEARCH_HASHTAGS, "hashtags");
}

View file

@ -21,6 +21,17 @@
#include <mastodont.h>
#include "session.h"
void content_search(struct session* ssn, mastodont_t* api, char** data);
enum search_tab
{
SEARCH_STATUSES,
SEARCH_ACCOUNTS,
SEARCH_HASHTAGS,
};
void search_page(struct session* ssn, mastodont_t* api, enum search_tab tab, char* content);
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);
#endif /* SEARCH_H */

View file

@ -22,6 +22,7 @@
/** Returns str. If NULL, returns empty string */
#define STR_NULL_EMPTY(str) ((str) ? (str) : "")
#define MAKE_FOCUSED_IF(tab, test_tab) ((tab) == test_tab ? "focused" : "")
#define CAT_TEXT(cat, cfg_cat) ((cat) == (cfg_cat)) ? "focused" : ""

View file

@ -1,31 +1,13 @@
<table class="search-tabs ui-table">
<table class="tabs ui-table">
<tr>
<td class="search-tab btn">
<form action="%s/search/statuses" method="get">
<label class="pointer">
<input type="hidden" name="q" value="%s">
<span class="search-tab-btn">%s</span>
<input type="submit" class="hidden">
</label>
</form>
<td>
<a href="%s/search/statuses?q=%s"><input class="tab-btn btn %s" type="button" value="%s"></a>
</td>
<td class="nav-prev btn">
<form action="%s/search/accounts" method="get">
<label class="pointer">
<input type="hidden" name="q" value="%s">
<span class="search-tab-btn">%s</span>
<input type="submit" class="hidden">
</label>
</form>
<td>
<a href="%s/search/accounts?q=%s"><input class="tab-btn btn %s" type="button" value="%s"></a>
</td>
<td class="nav-next btn">
<form action="%s/search/hashtags" method="get">
<label class="pointer">
<input type="hidden" name="q" value="%s">
<span class="search-tab-btn">%s</span>
<input type="submit" class="hidden">
</label>
</form>
<td>
<a href="%s/search/hashtags?q=%s"><input class="tab-btn btn %s" type="button" value="%s"></a>
</td>
</tr>
</table>