Refactor search tabs

FossilOrigin-Name: 77ae2a3ad81f7655791d0431d7312dc325da8c292ada210b9a0654d4183740a8
This commit is contained in:
nekobit 2022-08-19 17:43:42 +00:00
parent 9bcf209e5c
commit 52c011968f
5 changed files with 53 additions and 22 deletions

View file

@ -3,7 +3,7 @@ use strict;
use warnings;
use Exporter 'import';
our @EXPORTS = qw( content_search search_tags search_accounts search_statuses );
our @EXPORTS = qw( content_search content_search_tags content_search_accounts content_search_statuses search_tags search_accounts search_statuses );
use template_helpers 'to_template';
use status 'generate_status';
@ -30,20 +30,54 @@ sub search_page
to_template(\%vars, \$data->{'search.tt'});
}
# CONTENT
sub search_accounts
{
my ($ssn, $data, $search) = @_;
my %vars = (
prefix => '',
ssn => $ssn,
search => $search,
);
search_page($ssn, $data, SEARCH_CAT_ACCOUNTS, to_template(\%vars, \$data->{'search_accounts.tt'}));
to_template(\%vars, \$data->{'search_accounts.tt'})
}
sub search_statuses
{
my ($ssn, $data, $search) = @_;
my %vars = (
prefix => '',
ssn => $ssn,
search => $search,
);
to_template(\%vars, \$data->{'search_statuses.tt'})
}
sub search_tags
{
my ($ssn, $data, $search) = @_;
my %vars = (
prefix => '',
ssn => $ssn,
search => $search,
);
to_template(\%vars, \$data->{'search_tags.tt'})
}
sub content_search_accounts
{
my ($ssn, $data, $search) = @_;
search_page($ssn, $data, SEARCH_CAT_ACCOUNTS, search_accounts(@_));
}
sub content_search_statuses
{
my ($ssn, $data, $search) = @_;
@ -55,10 +89,10 @@ sub search_statuses
create_status => sub { generate_status($ssn, $data, shift); },
);
search_page($ssn, $data, SEARCH_CAT_STATUSES, to_template(\%vars, \$data->{'search_statuses.tt'}));
search_page($ssn, $data, SEARCH_CAT_STATUSES, search_statuses(@_));
}
sub search_tags
sub content_search_tags
{
my ($ssn, $data, $tags) = @_;
@ -68,7 +102,7 @@ sub search_tags
tags => $tags,
);
search_page($ssn, $data, SEARCH_CAT_TAGS, to_template(\%vars, \$data->{'search_tags.tt'}));
search_page($ssn, $data, SEARCH_CAT_TAGS, search_tags(@_));
}
sub content_search
@ -80,8 +114,9 @@ sub content_search
ssn => $ssn,
search => $search,
create_status => sub { generate_status($ssn, $data, shift); },
create_account => sub { generate_account_item($ssn, $data, shift); },
statuses => search_statuses,
accounts => search_accounts,
hashtags => search_tags,
);
to_template(\%vars, \$data->{'content_search.tt'});

View file

@ -164,8 +164,7 @@ void content_search_statuses(PATH_ARGS)
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");
PERL_STACK_SCALAR_CALL("search::content_search_statuses");
// Duplicate so we can free the TMPs
char* dup = PERL_GET_STACK_EXIT;
@ -211,7 +210,7 @@ void content_search_accounts(PATH_ARGS)
XPUSHs(newRV_noinc((SV*)template_files));
XPUSHs(newRV_noinc((SV*)perlify_search_results(&results)));
PERL_STACK_SCALAR_CALL("search::search_accounts");
PERL_STACK_SCALAR_CALL("search::content_search_accounts");
// Duplicate so we can free the TMPs
char* dup = PERL_GET_STACK_EXIT;

View file

@ -19,20 +19,16 @@
</table>
<div class="search-results">
<input type="radio" class="search-page-hidden hidden" id="statuses-results-hidden" name="searchpage" checked>
<input type="radio" class="search-page-hidden hidden" id="statuses-results-hidden" name="searchpage"[% UNLESS search.statuses %] disabled[% ELSE %] checked[% END %]>
<div class="statuses-results search-page">
[% FOREACH i IN search.statuses %]
[% create_status(i); %]
[% END %]
[% statuses %]
</div>
<input type="radio" class="search-page-hidden hidden" id="accounts-results-hidden" name="searchpage">
<input type="radio" class="search-page-hidden hidden" id="accounts-results-hidden" name="searchpage"[% UNLESS search.accounts %] disabled[% END %]>
<div class="accounts-results search-page">
[% FOREACH i IN search.accounts %]
[% create_account(i); %]
[% END %]
[% accounts %]
</div>
<input type="radio" class="search-page-hidden hidden" id="hashtags-results-hidden" name="searchpage">
<input type="radio" class="search-page-hidden hidden" id="hashtags-results-hidden" name="searchpage"[% UNLESS search.tags %] disabled[% END %]>
<div class="hashtags-results search-page">
TODO
[% hashtags %]
</div>
</div>

View file

@ -15,5 +15,5 @@
</table>
<div class="search-results">
[% results %]
[% content %]
</div>

View file

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