mirror of https://git.stjo.hn/planiverse
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:
parent
014228edc6
commit
1758952667
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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) 🤖 @endif
|
||||
@if ($account['locked']) 🔒 @endif
|
||||
</a>
|
||||
</span>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
|
@ -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');
|
||||
|
||||
|
|
Loading…
Reference in New Issue