Search tab results

FossilOrigin-Name: 68d1917ab69702c73a51670aad91abf4e6ff82ebc9278c5e70a148031f00444d
This commit is contained in:
nekobit 2022-08-19 17:00:53 +00:00
parent 785394e435
commit 9bcf209e5c
7 changed files with 87 additions and 6 deletions

15
dist/treebird.css vendored
View File

@ -276,6 +276,21 @@ table.ui-table td
padding-left: 27px;
}
.results-header
{
font-size: 1.4rem;
font-weight: normal;
padding: 8px 16px;
border-bottom: 1px solid #cacaca;
margin: 0;
}
.results-header .result
{
font-size: 1.7rem;
font-weight: bold;
}
#navbar .search-menu-dropdown
{
display: inline;

View File

@ -32,12 +32,12 @@ sub search_page
sub search_accounts
{
my ($ssn, $data, $accounts) = @_;
my ($ssn, $data, $search) = @_;
my %vars = (
prefix => '',
ssn => $ssn,
accounts => $accounts,
search => $search,
);
search_page($ssn, $data, SEARCH_CAT_ACCOUNTS, to_template(\%vars, \$data->{'search_accounts.tt'}));
@ -45,12 +45,14 @@ sub search_accounts
sub search_statuses
{
my ($ssn, $data, $statuses) = @_;
my ($ssn, $data, $search) = @_;
my %vars = (
prefix => '',
ssn => $ssn,
statuses => $statuses,
search => $search,
create_status => sub { generate_status($ssn, $data, shift); },
);
search_page($ssn, $data, SEARCH_CAT_STATUSES, to_template(\%vars, \$data->{'search_statuses.tt'}));

View File

@ -40,6 +40,7 @@
#include "../templates/search_accounts.ctt"
#include "../templates/search_statuses.ctt"
#include "../templates/search_tags.ctt"
#include "../templates/search.ctt"
#include "../templates/content_chats.ctt"
#include "../templates/chat.ctt"
#include "../templates/config_general.ctt"
@ -75,6 +76,7 @@ void init_template_files(pTHX)
hv_stores(template_files, "accounts.tt", newSVpv(data_accounts_tt, data_accounts_tt_size));
hv_stores(template_files, "account_item.tt", newSVpv(data_account_item_tt, data_account_item_tt_size));
hv_stores(template_files, "content_search.tt", newSVpv(data_content_search_tt, data_content_search_tt_size));
hv_stores(template_files, "search.tt", newSVpv(data_search_tt, data_search_tt_size));
hv_stores(template_files, "search_accounts.tt", newSVpv(data_search_accounts_tt, data_search_accounts_tt_size));
hv_stores(template_files, "search_statuses.tt", newSVpv(data_search_statuses_tt, data_search_statuses_tt_size));
hv_stores(template_files, "search_tags.tt", newSVpv(data_search_tags_tt, data_search_tags_tt_size));

View File

@ -159,10 +159,29 @@ void content_search_statuses(PATH_ARGS)
mastodont_search(api, &m_args, keystr(ssn->query.query), &storage, &args, &results);
// TODO
PERL_STACK_INIT;
HV* session_hv = perlify_session(ssn);
XPUSHs(newRV_noinc((SV*)session_hv));
XPUSHs(newRV_noinc((SV*)template_files));
XPUSHs(newRV_noinc((SV*)perlify_search_results(&results)));
PERL_STACK_SCALAR_CALL("search::search_statuses");
// Duplicate so we can free the TMPs
char* dup = PERL_GET_STACK_EXIT;
struct base_page b = {
.category = BASE_CAT_NONE,
.content = dup,
.session = session_hv,
.sidebar_left = NULL
};
render_base_page(&b, req, ssn, api);
mstdnt_cleanup_search_results(&results);
mastodont_storage_cleanup(&storage);
Safefree(dup);
}
void content_search_accounts(PATH_ARGS)
@ -186,7 +205,25 @@ void content_search_accounts(PATH_ARGS)
mastodont_search(api, &m_args, keystr(ssn->query.query), &storage, &args, &results);
// TODO
PERL_STACK_INIT;
HV* session_hv = perlify_session(ssn);
XPUSHs(newRV_noinc((SV*)session_hv));
XPUSHs(newRV_noinc((SV*)template_files));
XPUSHs(newRV_noinc((SV*)perlify_search_results(&results)));
PERL_STACK_SCALAR_CALL("search::search_accounts");
// Duplicate so we can free the TMPs
char* dup = PERL_GET_STACK_EXIT;
struct base_page b = {
.category = BASE_CAT_NONE,
.content = dup,
.session = session_hv,
.sidebar_left = NULL
};
render_base_page(&b, req, ssn, api);
mstdnt_cleanup_search_results(&results);
mastodont_storage_cleanup(&storage);

19
templates/search.tt Normal file
View File

@ -0,0 +1,19 @@
<h1 class="results-header">Showing results for <span class="result">&quot;[% ssn.query.query %]&quot;</span></h1>
<table class="tabs ui-table">
<tr>
<td>
<a href="/search/statuses?q="><input class="tab-btn btn[% IF tab == 0 %] active[% END %]" type="button" value="Statuses"></a>
</td>
<td>
<a href="/search/accounts?q="><input class="tab-btn btn[% IF tab == 1 %] active[% END %]" type="button" value="Accounts"></a>
</td>
<td>
<a href="/search/hashtags?q="><input class="tab-btn btn [% IF tab == 2 %] active[% END %]" type="button" value="Hashtags"></a>
</td>
</tr>
</table>
<div class="search-results">
[% results %]
</div>

View File

@ -0,0 +1,3 @@
[% FOREACH i IN search.accounts %]
[% create_account(i); %]
[% END %]

View File

@ -0,0 +1,3 @@
[% FOREACH i IN search.statuses %]
[% create_status(i); %]
[% END %]