Search all and searchbox tweaks
FossilOrigin-Name: 4130b59a244b1e0a82023c9e18f50ebe731348ecc06ad3b1df1e1390a455636c
This commit is contained in:
parent
3ffbfb2f13
commit
5904362b1a
|
@ -0,0 +1 @@
|
|||
<svg width="20" height="20" fill="none" stroke="#000000" stroke-linecap="round" stroke-linejoin="round" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><circle cx="10.107" cy="8.7642" r="6.7391" stroke-width="1.6848"/><line x1="18.531" x2="14.866" y1="17.188" y2="13.524" stroke-width="1.6848"/><path d="m14.756 20.738 1.9607 1.9607 1.9091-1.9297" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.6554"/></svg>
|
After Width: | Height: | Size: 446 B |
|
@ -258,6 +258,19 @@ table.ui-table td
|
|||
border-right: 1px solid #dadada;
|
||||
}
|
||||
|
||||
#searchbox
|
||||
{
|
||||
padding-left: 26px;
|
||||
}
|
||||
|
||||
#navbar .searchbox-container .search-menu
|
||||
{
|
||||
position: relative;
|
||||
left: 30px;
|
||||
top: 6px;
|
||||
stroke: #606060;
|
||||
}
|
||||
|
||||
#leftbar ul
|
||||
{
|
||||
margin: 0;
|
||||
|
|
|
@ -5,7 +5,7 @@ use Data::Dumper;
|
|||
|
||||
use Exporter 'import';
|
||||
|
||||
our @EXPORT = qw( account content_statuses );
|
||||
our @EXPORT = qw( account content_statuses generate_account_list generate_account_item );
|
||||
|
||||
use template_helpers 'to_template';
|
||||
use l10n 'lang';
|
||||
|
|
|
@ -44,6 +44,10 @@ sub get_icon_svg
|
|||
public => '<svg class="visibility vis-public" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="2" y1="12" x2="22" y2="12"></line><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"></path></svg>',
|
||||
|
||||
follow => '<svg class="follow" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="8.5" cy="7" r="4"></circle><line x1="20" y1="8" x2="20" y2="14"></line><line x1="23" y1="11" x2="17" y2="11"></line></svg>',
|
||||
|
||||
search => '<svg class="search" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
|
||||
|
||||
'search-menu' => '<svg class="search-menu" width="20" height="20" fill="none" stroke="#000000" stroke-linecap="round" stroke-linejoin="round" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><circle cx="10.107" cy="8.7642" r="6.7391" stroke-width="1.6848"/><line x1="18.531" x2="14.866" y1="17.188" y2="13.524" stroke-width="1.6848"/><path d="m14.756 20.738 1.9607 1.9607 1.9091-1.9297" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.6554"/></svg>',
|
||||
);
|
||||
|
||||
$res{$_[0]};
|
||||
|
|
|
@ -6,9 +6,11 @@ use l10n qw( &lang %L10N );
|
|||
use notifications qw( generate_notification_compact content_notifications );
|
||||
use template_helpers qw( &to_template );
|
||||
use timeline;
|
||||
use icons 'get_icon';
|
||||
use status;
|
||||
use account;
|
||||
use lists;
|
||||
use search;
|
||||
|
||||
# my $template = Template->new(
|
||||
# {
|
||||
|
@ -32,6 +34,7 @@ sub base_page
|
|||
title => $L10N{'EN_US'}->{'APP_NAME'},
|
||||
lang => \&lang,
|
||||
main => $main,
|
||||
icon => \&get_icon,
|
||||
sidebar_opacity => $ssn->{config}->{sidebar_opacity} / 255,
|
||||
acct => $ssn->{account},
|
||||
data => $data,
|
||||
|
|
|
@ -6,6 +6,8 @@ use Exporter 'import';
|
|||
our @EXPORTS = qw( content_search search_tags search_accounts search_statuses );
|
||||
|
||||
use template_helpers 'to_template';
|
||||
use status 'generate_status';
|
||||
use account 'generate_account_item';
|
||||
|
||||
use constant
|
||||
{
|
||||
|
@ -28,33 +30,19 @@ sub search_page
|
|||
to_template(\%vars, \$data->{'search.tt'});
|
||||
}
|
||||
|
||||
sub search_tags
|
||||
{
|
||||
my ($ssn, $data, $tags) = @_;
|
||||
|
||||
my %vars = (
|
||||
prefix => '',
|
||||
ssn => $ssn,
|
||||
statuses => $statuses,
|
||||
);
|
||||
|
||||
search_page($ssn, $data, SEARCH_CAT_STATUSES, to_template(\%vars, \$data->{'search_tags.tt'}));
|
||||
}
|
||||
|
||||
sub search_accounts
|
||||
{
|
||||
my ($ssn, $data, $statuses) = @_;
|
||||
my ($ssn, $data, $accounts) = @_;
|
||||
|
||||
my %vars = (
|
||||
prefix => '',
|
||||
ssn => $ssn,
|
||||
statuses => $statuses,
|
||||
accounts => $accounts,
|
||||
);
|
||||
|
||||
search_page($ssn, $data, SEARCH_CAT_STATUSES, to_template(\%vars, \$data->{'search_accounts.tt'}));
|
||||
search_page($ssn, $data, SEARCH_CAT_ACCOUNTS, to_template(\%vars, \$data->{'search_accounts.tt'}));
|
||||
}
|
||||
|
||||
|
||||
sub search_statuses
|
||||
{
|
||||
my ($ssn, $data, $statuses) = @_;
|
||||
|
@ -68,6 +56,19 @@ sub search_statuses
|
|||
search_page($ssn, $data, SEARCH_CAT_STATUSES, to_template(\%vars, \$data->{'search_statuses.tt'}));
|
||||
}
|
||||
|
||||
sub search_tags
|
||||
{
|
||||
my ($ssn, $data, $tags) = @_;
|
||||
|
||||
my %vars = (
|
||||
prefix => '',
|
||||
ssn => $ssn,
|
||||
tags => $tags,
|
||||
);
|
||||
|
||||
search_page($ssn, $data, SEARCH_CAT_TAGS, to_template(\%vars, \$data->{'search_tags.tt'}));
|
||||
}
|
||||
|
||||
sub content_search
|
||||
{
|
||||
my ($ssn, $data, $search) = @_;
|
||||
|
@ -76,6 +77,9 @@ sub content_search
|
|||
prefix => '',
|
||||
ssn => $ssn,
|
||||
search => $search,
|
||||
|
||||
create_status => sub { generate_status($ssn, $data, shift); },
|
||||
create_account => sub { generate_account_item($ssn, $data, shift); },
|
||||
);
|
||||
|
||||
to_template(\%vars, \$data->{'content_search.tt'});
|
||||
|
|
|
@ -36,6 +36,10 @@
|
|||
#include "../templates/navigation.ctt"
|
||||
#include "../templates/accounts.ctt"
|
||||
#include "../templates/account_item.ctt"
|
||||
#include "../templates/content_search.ctt"
|
||||
#include "../templates/search_accounts.ctt"
|
||||
#include "../templates/search_statuses.ctt"
|
||||
#include "../templates/search_tags.ctt"
|
||||
|
||||
PerlInterpreter* my_perl;
|
||||
HV* template_files;
|
||||
|
@ -62,6 +66,10 @@ void init_template_files(pTHX)
|
|||
hv_stores(template_files, "navigation.tt", newSVpv(data_navigation_tt, data_navigation_tt_size));
|
||||
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_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));
|
||||
}
|
||||
|
||||
void cleanup_template_files()
|
||||
|
|
98
src/search.c
98
src/search.c
|
@ -68,13 +68,6 @@ void content_search_all(PATH_ARGS)
|
|||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
char* out_data = NULL;
|
||||
char* statuses_html = NULL;
|
||||
char* accounts_html = NULL;
|
||||
char* tags_html = NULL,
|
||||
* tags_graph = NULL,
|
||||
* tags_bars = NULL,
|
||||
* tags_page = NULL;
|
||||
struct mstdnt_storage storage = { 0 };
|
||||
struct mstdnt_search_args args = {
|
||||
.account_id = NULL,
|
||||
|
@ -90,72 +83,43 @@ void content_search_all(PATH_ARGS)
|
|||
};
|
||||
struct mstdnt_search_results results = { 0 };
|
||||
|
||||
if (mastodont_search(api,
|
||||
&m_args,
|
||||
keystr(ssn->query.query),
|
||||
&storage,
|
||||
&args,
|
||||
&results) == 0)
|
||||
{
|
||||
// Statuses, make sure to set the highlight word
|
||||
struct construct_statuses_args statuses_args = {
|
||||
.highlight_word = keystr(ssn->query.query),
|
||||
};
|
||||
|
||||
statuses_html = construct_statuses(ssn, api, results.statuses, results.statuses_len, &statuses_args, NULL);
|
||||
if (!statuses_html)
|
||||
statuses_html = construct_error("No statuses", E_ERROR, 1, NULL);
|
||||
mastodont_search(api, &m_args, keystr(ssn->query.query), &storage, &args, &results);
|
||||
|
||||
// Accounts
|
||||
accounts_html = construct_accounts(api, results.accts, results.accts_len, 0, NULL);
|
||||
if (!accounts_html)
|
||||
accounts_html = construct_error("No accounts", E_ERROR, 1, NULL);
|
||||
|
||||
// Hashtags
|
||||
tags_html = construct_hashtags(results.tags, results.tags_len, NULL);
|
||||
if (!tags_html)
|
||||
tags_html = construct_error("No hashtags", E_ERROR, 1, NULL);
|
||||
|
||||
tags_bars = construct_hashtags_graph(results.tags,
|
||||
results.tags_len,
|
||||
14,
|
||||
NULL);
|
||||
if (tags_bars)
|
||||
tags_graph = construct_bar_graph_container(tags_bars, NULL);
|
||||
|
||||
free(tags_bars);
|
||||
}
|
||||
|
||||
easprintf(&tags_page, "%s%s", STR_NULL_EMPTY(tags_graph), tags_html);
|
||||
perl_lock();
|
||||
dSP;
|
||||
ENTER;
|
||||
SAVETMPS;
|
||||
PUSHMARK(SP);
|
||||
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)));
|
||||
|
||||
// Construct search page
|
||||
struct search_all_template tdata = {
|
||||
.accounts = "Accounts",
|
||||
.hashtags = "Hashtags",
|
||||
.statuses = "Statuses",
|
||||
.statuses_results = statuses_html,
|
||||
.hashtags_results = tags_page,
|
||||
.accounts_results = accounts_html
|
||||
};
|
||||
out_data = tmpl_gen_search_all(&tdata, NULL);
|
||||
// ARGS
|
||||
PUTBACK;
|
||||
call_pv("search::content_search", G_SCALAR);
|
||||
SPAGAIN;
|
||||
|
||||
// Duplicate so we can free the TMPs
|
||||
char* dup = savesharedsvpv(POPs);
|
||||
|
||||
PUTBACK;
|
||||
FREETMPS;
|
||||
LEAVE;
|
||||
perl_unlock();
|
||||
|
||||
struct base_page b = {
|
||||
.category = BASE_CAT_NONE,
|
||||
.content = out_data,
|
||||
.content = dup,
|
||||
.session = session_hv,
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
free(out_data);
|
||||
free(statuses_html);
|
||||
free(accounts_html);
|
||||
free(tags_html);
|
||||
free(tags_graph);
|
||||
free(tags_page);
|
||||
mstdnt_cleanup_search_results(&results);
|
||||
mastodont_storage_cleanup(&storage);
|
||||
Safefree(dup);
|
||||
}
|
||||
|
||||
void content_search_statuses(PATH_ARGS)
|
||||
|
@ -299,3 +263,15 @@ void content_search_hashtags(PATH_ARGS)
|
|||
mstdnt_cleanup_search_results(&results);
|
||||
mastodont_storage_cleanup(&storage);
|
||||
}
|
||||
|
||||
HV* perlify_search_results(struct mstdnt_search_results* results)
|
||||
{
|
||||
if (!results) return NULL;
|
||||
|
||||
HV* search_hv = newHV();
|
||||
hvstores_ref(search_hv, "accounts", perlify_accounts(results->accts, results->accts_len));
|
||||
hvstores_ref(search_hv, "statuses", perlify_statuses(results->statuses, results->statuses_len));
|
||||
// TODO tags
|
||||
|
||||
return search_hv;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <mastodont.h>
|
||||
#include "session.h"
|
||||
#include "path.h"
|
||||
#include "global_perl.h"
|
||||
|
||||
enum search_tab
|
||||
{
|
||||
|
@ -38,5 +39,6 @@ void content_search_all(PATH_ARGS);
|
|||
void content_search_statuses(PATH_ARGS);
|
||||
void content_search_accounts(PATH_ARGS);
|
||||
void content_search_hashtags(PATH_ARGS);
|
||||
HV* perlify_search_results(struct mstdnt_search_results* results);
|
||||
|
||||
#endif /* SEARCH_H */
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<table class="tabs ui-table">
|
||||
<tr>
|
||||
<td>
|
||||
<label for="statuses-results-hidden">
|
||||
<span class="tab-btn btn">Statuses</span>
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
<label for="accounts-results-hidden">
|
||||
<span class="tab-btn btn">Accounts</span>
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
<label for="hashtags-results-hidden">
|
||||
<span class="tab-btn btn">Hashtags</span>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="search-results">
|
||||
<input type="radio" class="search-page-hidden hidden" id="statuses-results-hidden" name="searchpage" checked>
|
||||
<div class="statuses-results search-page">
|
||||
[% FOREACH i IN search.statuses %]
|
||||
[% create_status(i); %]
|
||||
[% END %]
|
||||
</div>
|
||||
<input type="radio" class="search-page-hidden hidden" id="accounts-results-hidden" name="searchpage">
|
||||
<div class="accounts-results search-page">
|
||||
[% FOREACH i IN search.accounts %]
|
||||
[% create_account(i); %]
|
||||
[% END %]
|
||||
</div>
|
||||
<input type="radio" class="search-page-hidden hidden" id="hashtags-results-hidden" name="searchpage">
|
||||
<div class="hashtags-results search-page">
|
||||
TODO
|
||||
</div>
|
||||
</div>
|
|
@ -25,7 +25,7 @@
|
|||
<label for="leftbar-show">
|
||||
<svg class="leftbar-btn navbar-btn" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>
|
||||
</label>
|
||||
<a href="{{ %s : prefix }}/"><img src="/treebird_logo.png" height="42"></a>
|
||||
<a href="$prefix/"><img src="/treebird_logo.png" height="42"></a>
|
||||
<span class="info">$title</span>
|
||||
<label for="rightbar-show">
|
||||
<svg class="rightbar-btn navbar-btn" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 17H2a3 3 0 0 0 3-3V9a7 7 0 0 1 14 0v5a3 3 0 0 0 3 3zm-8.27 4a2 2 0 0 1-3.46 0"></path></svg>
|
||||
|
@ -40,9 +40,9 @@
|
|||
<a href="login" id="login-header">Login / Register</a>
|
||||
[%- END %]
|
||||
<!-- Searchbox -->
|
||||
<form action="{{ %s : prefix }}/search" method="get">
|
||||
<input type="text" class="group group-left group-inputbox" placeholder="[% lang('SEARCH_PLACEHOLDER') %]" id="searchbox" name="q"><!-- i hate HTML
|
||||
--><input type="submit" class="btn group group-right" value="[% lang('SEARCH_BUTTON') %]">
|
||||
<form class="searchbox-container" action="$prefix/search" method="get">
|
||||
[% icon('search-menu') %]
|
||||
<input type="text" class="group group-left group-inputbox" placeholder="[% lang('SEARCH_PLACEHOLDER') %]" id="searchbox" name="q"><input type="submit" class="btn group group-right" value="[% lang('SEARCH_BUTTON') %]">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue