Implemented searching for accounts, but commented out the nav link

Implemented searching for accounts using the /accounts/search API
end-point. For some reason Guzzle consistently throws an exception,
so for now I've commented out the nav link to the search page.
This commit is contained in:
St John Karp 2018-10-09 20:12:14 -07:00
parent 014228edc6
commit 1758952667
4 changed files with 91 additions and 0 deletions

View File

@ -67,4 +67,43 @@ class AccountController extends Controller
return redirect()->route('account', ['account_id' => $account_id])
->with('relationship', $relationship);
}
public function show_search()
{
if (session()->has('accounts'))
{
// The user is coming here after peforming a search.
$accounts = session('accounts');
}
else
{
$accounts = [];
}
$vars = [
'accounts' => $accounts,
'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1]
];
return view('search_accounts', $vars);
}
public function search(Request $request)
{
$user = session('user');
# Verify we have an actual account to search for.
if (!$request->has('account'))
{
abort(400);
}
$accounts = Mastodon::domain(env('MASTODON_DOMAIN'))
->token($user->token)
->get('/accounts/search', ['q' => $request->account]);
return redirect()->route('show_search_accounts')
->with('accounts', $accounts);
}
}

View File

@ -3,5 +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_accounts') }}">Search</a></li>-->
</ul>
</nav>

View File

@ -0,0 +1,43 @@
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ $mastodon_domain }} | Search</title>
<link rel="stylesheet" href="{{ url('css/styles.css') }}" />
</head>
<body>
<h1>{{ $mastodon_domain }} | Search</h1>
@component('navigation')
@endcomponent
<form method="post" action="{{ route('search_accounts') }}">
<input type="text" name="account" placeholder="Account" required autofocus />
<input type="submit" value="Search" />
{{ csrf_field() }}
</form>
<ul>
@foreach ($accounts as $account)
<li>
<span class="account" title="{{ $account['acct'] }}">
<a href="{{ $account['url'] }}">
<img
src="{{ $account['avatar'] }}"
alt="{{ $account['acct'] }}"
class="avatar"
/>
{{ $account['display_name'] }}
@if ($account['bot'] ?? false) &#129302; @endif
@if ($account['locked']) &#128274; @endif
</a>
</span>
</li>
@endforeach
</ul>
</body>
</html>

View File

@ -71,6 +71,14 @@ Route::get('/account/{account_id}/unfollow', 'AccountController@unfollow_account
->name('unfollow')
->middleware('authorize');
Route::get('/accounts/search', 'AccountController@show_search')
->name('show_search_accounts')
->middleware('authorize');
Route::post('/accounts/search', 'AccountController@search')
->name('search_accounts')
->middleware('authorize');
Route::get('/login', 'LoginController@login')
->name('login');