Handle no search results
This commit is contained in:
parent
2c8dee8cf5
commit
0c1e041b29
|
@ -61,7 +61,6 @@ tests locally:
|
||||||
|
|
||||||
## TODOs
|
## TODOs
|
||||||
|
|
||||||
1. Do something if a search returns nothing
|
|
||||||
1. Hide ancient posts
|
1. Hide ancient posts
|
||||||
1. Put a link to search_page somewhere
|
1. Put a link to search_page somewhere
|
||||||
1. "All new posts flagged" mode (require approval for new posts)
|
1. "All new posts flagged" mode (require approval for new posts)
|
||||||
|
|
|
@ -59,13 +59,19 @@ sub search($self) {
|
||||||
$v->required('q' )->size(1, 2_047);
|
$v->required('q' )->size(1, 2_047);
|
||||||
$v->optional('page');
|
$v->optional('page');
|
||||||
|
|
||||||
|
if ($v->has_error) {
|
||||||
|
$self->stash(status => 400)
|
||||||
|
}
|
||||||
|
else {
|
||||||
$search_query = $v->param('q');
|
$search_query = $v->param('q');
|
||||||
$this_page = $v->param('page') || 1;
|
$this_page = $v->param('page') || 1;
|
||||||
$last_page = $self->page->last_page_for($search_query);
|
$last_page = $self->page->last_page_for($search_query);
|
||||||
$base_path = $self->url_for->query(q => $search_query);
|
$base_path = $self->url_for->query(q => $search_query);
|
||||||
$search_results = $self->page->search($search_query, $this_page);
|
$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(
|
$self->stash(
|
||||||
|
|
|
@ -21,7 +21,10 @@ subtest 'Search after CAPTCHA', sub {
|
||||||
$t->get_ok('/human/search')->status_is(200)
|
$t->get_ok('/human/search')->status_is(200)
|
||||||
->text_like(h2 => qr/Search Posts/);
|
->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/);
|
->text_like(h3 => qr/Results/);
|
||||||
|
|
||||||
$t->get_ok("/human/search?q=$invalid_query")->status_is(400)
|
$t->get_ok("/human/search?q=$invalid_query")->status_is(400)
|
||||||
|
|
Loading…
Reference in a new issue