From 657b6489387a24fd64de77b017704d8cdebeae61 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Wed, 4 May 2022 00:11:17 +0000 Subject: [PATCH] Search functions FossilOrigin-Name: 1079a61c79c7ade533027a59b1bcc3641b50604851f13dbc82aeed9d9c044c7d --- src/account.c | 1 - src/main.c | 9 ++++----- src/query.c | 3 --- src/search.c | 24 +++++++++++++++++++++--- src/search.h | 13 ++++++++++++- src/string_helpers.h | 1 + static/search.html | 32 +++++++------------------------- 7 files changed, 45 insertions(+), 38 deletions(-) diff --git a/src/account.c b/src/account.c index d40fa41..7c54796 100644 --- a/src/account.c +++ b/src/account.c @@ -38,7 +38,6 @@ #include "../static/bookmarks_page.chtml" #define FOLLOWS_YOU_HTML "%s" -#define MAKE_FOCUSED_IF(tab, test_tab) ((tab) == test_tab ? "focused" : "") char* load_account_info(struct mstdnt_account* acct, size_t* size) diff --git a/src/main.c b/src/main.c index c86383a..15a84d8 100644 --- a/src/main.c +++ b/src/main.c @@ -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 }, diff --git a/src/query.c b/src/query.c index 779c196..0153e09 100644 --- a/src/query.c +++ b/src/query.c @@ -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; diff --git a/src/search.c b/src/search.c index a65796b..d063eb4 100644 --- a/src/search.c +++ b/src/search.c @@ -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"); } diff --git a/src/search.h b/src/search.h index 56423eb..afdd1d4 100644 --- a/src/search.h +++ b/src/search.h @@ -21,6 +21,17 @@ #include #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 */ diff --git a/src/string_helpers.h b/src/string_helpers.h index 8afd817..d29f5f5 100644 --- a/src/string_helpers.h +++ b/src/string_helpers.h @@ -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" : "" diff --git a/static/search.html b/static/search.html index 0aa44c0..c9fefd5 100644 --- a/static/search.html +++ b/static/search.html @@ -1,31 +1,13 @@ - +
- - -
-
- -
+
+ + +