planiverse

A minimalist, no-JS front-end for Mastodon.
git clone https://git.mulligrubs.me/planiverse
Log | Files | Refs | README | LICENSE

commit 175895266796ab19ac0e5dd8a4df5607552255b8
parent 014228edc65c6270470559608cc83cdab84fae2e
Author: St John Karp <stjohn@fuzzjunket.com>
Date:   Tue,  9 Oct 2018 20:12:14 -0700

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.

Diffstat:
Mapp/Http/Controllers/AccountController.php | 39+++++++++++++++++++++++++++++++++++++++
Mresources/views/navigation.blade.php | 1+
Aresources/views/search_accounts.blade.php | 43+++++++++++++++++++++++++++++++++++++++++++
Mroutes/web.php | 8++++++++
4 files changed, 91 insertions(+), 0 deletions(-)

diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php @@ -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); + } } diff --git a/resources/views/navigation.blade.php b/resources/views/navigation.blade.php @@ -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> diff --git a/resources/views/search_accounts.blade.php b/resources/views/search_accounts.blade.php @@ -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> diff --git a/routes/web.php b/routes/web.php @@ -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');