mirror of https://git.stjo.hn/planiverse
Consolidate search logic into one method/route
Put both show search and run search into the same route. This prevents Lynx from thinking the search results were from a GET request and caching the contents of the search page.
This commit is contained in:
parent
912929cf02
commit
d3927063c5
|
@ -11,32 +11,6 @@ use Illuminate\Http\Request;
|
|||
*/
|
||||
class SearchController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the page that lets users search across Accounts and Statuses.
|
||||
*
|
||||
* @return Illuminate\View\View The search page.
|
||||
*/
|
||||
public function show_search()
|
||||
{
|
||||
if (session()->has('results'))
|
||||
{
|
||||
# The user is coming here after peforming a search.
|
||||
|
||||
$results = session('results');
|
||||
}
|
||||
else
|
||||
{
|
||||
$results = null;
|
||||
}
|
||||
|
||||
$vars = [
|
||||
'results' => $results,
|
||||
'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1]
|
||||
];
|
||||
|
||||
return view('search', $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a search request.
|
||||
*
|
||||
|
@ -49,17 +23,23 @@ class SearchController extends Controller
|
|||
$user = session('user');
|
||||
|
||||
# Verify we have an actual search term.
|
||||
if (!$request->has('search_term'))
|
||||
if ($request->has('search_term'))
|
||||
{
|
||||
abort(400);
|
||||
# Query the search end-point.
|
||||
$results = Mastodon::domain(env('MASTODON_DOMAIN'))
|
||||
->token($user->token)
|
||||
->get('/search', ['q' => $request->search_term]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$results = null;
|
||||
}
|
||||
|
||||
# Query the search end-point.
|
||||
$results = Mastodon::domain(env('MASTODON_DOMAIN'))
|
||||
->token($user->token)
|
||||
->get('/search', ['q' => $request->search_term]);
|
||||
$vars = [
|
||||
'results' => $results,
|
||||
'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1]
|
||||
];
|
||||
|
||||
return redirect()->route('show_search')
|
||||
->with('results', $results);
|
||||
return view('search', $vars);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
<li><a href="{{ route('home') }}">Timeline</a></li>
|
||||
<li><a href="{{ route('public') }}">Public Timeline</a></li>
|
||||
<li><a href="{{ route('notifications') }}">Notifications</a></li>
|
||||
<li><a href="{{ route('show_search') }}">Search</a></li>
|
||||
<li><a href="{{ route('search') }}">Search</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
|
|
@ -71,11 +71,7 @@ Route::get('/account/{account_id}/unfollow', 'AccountController@unfollow_account
|
|||
->name('unfollow')
|
||||
->middleware('authorize');
|
||||
|
||||
Route::get('/search', 'SearchController@show_search')
|
||||
->name('show_search')
|
||||
->middleware('authorize');
|
||||
|
||||
Route::post('/search', 'SearchController@search')
|
||||
Route::match(['get', 'post'], '/search', 'SearchController@search')
|
||||
->name('search')
|
||||
->middleware('authorize');
|
||||
|
||||
|
|
Loading…
Reference in New Issue