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
|
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.
|
* Process a search request.
|
||||||
*
|
*
|
||||||
|
@ -49,17 +23,23 @@ class SearchController extends Controller
|
||||||
$user = session('user');
|
$user = session('user');
|
||||||
|
|
||||||
# Verify we have an actual search term.
|
# 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.
|
$vars = [
|
||||||
$results = Mastodon::domain(env('MASTODON_DOMAIN'))
|
'results' => $results,
|
||||||
->token($user->token)
|
'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1]
|
||||||
->get('/search', ['q' => $request->search_term]);
|
];
|
||||||
|
|
||||||
return redirect()->route('show_search')
|
return view('search', $vars);
|
||||||
->with('results', $results);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
<li><a href="{{ route('home') }}">Timeline</a></li>
|
<li><a href="{{ route('home') }}">Timeline</a></li>
|
||||||
<li><a href="{{ route('public') }}">Public Timeline</a></li>
|
<li><a href="{{ route('public') }}">Public Timeline</a></li>
|
||||||
<li><a href="{{ route('notifications') }}">Notifications</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>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
@ -71,11 +71,7 @@ Route::get('/account/{account_id}/unfollow', 'AccountController@unfollow_account
|
||||||
->name('unfollow')
|
->name('unfollow')
|
||||||
->middleware('authorize');
|
->middleware('authorize');
|
||||||
|
|
||||||
Route::get('/search', 'SearchController@show_search')
|
Route::match(['get', 'post'], '/search', 'SearchController@search')
|
||||||
->name('show_search')
|
|
||||||
->middleware('authorize');
|
|
||||||
|
|
||||||
Route::post('/search', 'SearchController@search')
|
|
||||||
->name('search')
|
->name('search')
|
||||||
->middleware('authorize');
|
->middleware('authorize');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue