Handle no search results

This commit is contained in:
swaggboi 2023-10-28 01:42:36 -04:00
parent 2c8dee8cf5
commit 0c1e041b29
3 changed files with 16 additions and 8 deletions

View File

@ -61,7 +61,6 @@ tests locally:
## TODOs
1. Do something if a search returns nothing
1. Hide ancient posts
1. Put a link to search_page somewhere
1. "All new posts flagged" mode (require approval for new posts)

View File

@ -59,13 +59,19 @@ sub search($self) {
$v->required('q' )->size(1, 2_047);
$v->optional('page');
$search_query = $v->param('q');
$this_page = $v->param('page') || 1;
$last_page = $self->page->last_page_for($search_query);
$base_path = $self->url_for->query(q => $search_query);
$search_results = $self->page->search($search_query, $this_page);
if ($v->has_error) {
$self->stash(status => 400)
}
else {
$search_query = $v->param('q');
$this_page = $v->param('page') || 1;
$last_page = $self->page->last_page_for($search_query);
$base_path = $self->url_for->query(q => $search_query);
$search_results = $self->page->search($search_query, $this_page);
$self->stash(status => 400) if $v->has_error;
$self->stash(status => 404, error => 'No posts found. 🔎')
unless scalar @{$search_results};
}
}
$self->stash(

View File

@ -21,7 +21,10 @@ subtest 'Search after CAPTCHA', sub {
$t->get_ok('/human/search')->status_is(200)
->text_like(h2 => qr/Search Posts/);
$t->get_ok('/human/search?q=test')->status_is(200)
$t->get_ok('/human/search?q=aaaaaaaaaa')->status_is(404)
->text_like(p => qr/No posts found/);
$t->get_ok('/human/search?q=lmao')->status_is(200)
->text_like(h3 => qr/Results/);
$t->get_ok("/human/search?q=$invalid_query")->status_is(400)