From 52c011968f5aa792f3b2777e64b096e01d8a117b Mon Sep 17 00:00:00 2001 From: nekobit Date: Fri, 19 Aug 2022 17:43:42 +0000 Subject: [PATCH] Refactor search tabs FossilOrigin-Name: 77ae2a3ad81f7655791d0431d7312dc325da8c292ada210b9a0654d4183740a8 --- perl/search.pm | 51 ++++++++++++++++++++++++++++++------ src/search.c | 5 ++-- templates/content_search.tt | 16 +++++------ templates/search.tt | 2 +- templates/search_statuses.tt | 1 + 5 files changed, 53 insertions(+), 22 deletions(-) diff --git a/perl/search.pm b/perl/search.pm index 91015fb..61be55b 100644 --- a/perl/search.pm +++ b/perl/search.pm @@ -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'}); diff --git a/src/search.c b/src/search.c index 46a334d..5377e63 100644 --- a/src/search.c +++ b/src/search.c @@ -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; diff --git a/templates/content_search.tt b/templates/content_search.tt index e8312ff..f8a931f 100644 --- a/templates/content_search.tt +++ b/templates/content_search.tt @@ -19,20 +19,16 @@
- +
- [% FOREACH i IN search.statuses %] - [% create_status(i); %] - [% END %] + [% statuses %]
- +
- [% FOREACH i IN search.accounts %] - [% create_account(i); %] - [% END %] + [% accounts %]
- +
- TODO + [% hashtags %]
diff --git a/templates/search.tt b/templates/search.tt index c2250af..ece7d55 100644 --- a/templates/search.tt +++ b/templates/search.tt @@ -15,5 +15,5 @@
- [% results %] + [% content %]
diff --git a/templates/search_statuses.tt b/templates/search_statuses.tt index 24b4e1d..0b0ac8b 100644 --- a/templates/search_statuses.tt +++ b/templates/search_statuses.tt @@ -1,3 +1,4 @@ [% FOREACH i IN search.statuses %] [% create_status(i); %] [% END %] +