Skip to content

Commit

Permalink
Define root view on a per-controller basis
Browse files Browse the repository at this point in the history
  • Loading branch information
andyksaw committed Jan 11, 2025
1 parent 233337c commit 9dba923
Show file tree
Hide file tree
Showing 35 changed files with 600 additions and 99 deletions.
17 changes: 17 additions & 0 deletions app/Domains/Manage/RendersManageApp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Domains\Manage;

use Illuminate\Contracts\Support\Arrayable;
use Inertia\Inertia;
use Inertia\Response;

trait RendersManageApp
{
public function inertiaRender(string $component, array|Arrayable $props = []): Response
{
Inertia::setRootView('manage.app');

return Inertia::render($component, $props);
}
}
17 changes: 17 additions & 0 deletions app/Domains/Review/RendersReviewApp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Domains\Review;

use Illuminate\Contracts\Support\Arrayable;
use Inertia\Inertia;
use Inertia\Response;

trait RendersReviewApp
{
public function inertiaRender(string $component, array|Arrayable $props = []): Response
{
Inertia::setRootView('review.app');

return Inertia::render($component, $props);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

namespace App\Http\Controllers\Manage\Accounts;

use App\Domains\Manage\RendersManageApp;
use App\Domains\MinecraftEventBus\Events\MinecraftPlayerUpdated;
use App\Models\Account;
use App\Models\Badge;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Inertia\Inertia;

class AccountBadgeController
{
use RendersManageApp;

public function index(Request $request, Account $account)
{
Gate::authorize('viewAny', Account::class);

$badges = Badge::get();
$accountBadgeIds = $account->badges->pluck(Badge::primaryKey());

return Inertia::render('Accounts/AccountBadgeSelect', [
return $this->inertiaRender('Accounts/AccountBadgeSelect', [
'badges' => $badges,
'account_badge_ids' => $accountBadgeIds ?? [],
'account_id' => $account->getKey(),
Expand Down
13 changes: 7 additions & 6 deletions app/Http/Controllers/Manage/Accounts/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Http\Controllers\Manage\Accounts;

use App\Core\Rules\DiscourseUsernameRule;
use App\Domains\Registration\Events\AccountCreated;
use App\Domains\Manage\RendersManageApp;
use App\Domains\Registration\UseCases\CreateUnactivatedAccount;
use App\Http\Controllers\WebController;
use App\Http\Filters\EqualFilter;
Expand All @@ -15,10 +15,11 @@
use Illuminate\Support\Facades\Pipeline;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Password;
use Inertia\Inertia;

class AccountController extends WebController
{
use RendersManageApp;

public function index(Request $request)
{
Gate::authorize('viewAny', Account::class);
Expand All @@ -38,7 +39,7 @@ public function index(Request $request)
if ($request->wantsJson()) {
return $accounts;
}
return Inertia::render('Accounts/AccountList', compact('accounts'));
return $this->inertiaRender('Accounts/AccountList', compact('accounts'));
}

public function show(Account $account)
Expand All @@ -54,14 +55,14 @@ public function show(Account $account)
'donations',
]);

return Inertia::render('Accounts/AccountShow', compact('account'));
return $this->inertiaRender('Accounts/AccountShow', compact('account'));
}

public function create()
{
Gate::authorize('create', Account::class);

return Inertia::render('Accounts/AccountCreate');
return $this->inertiaRender('Accounts/AccountCreate');
}

public function store(Request $request, CreateUnactivatedAccount $createUnactivatedAccount)
Expand Down Expand Up @@ -97,7 +98,7 @@ public function edit(Account $account)
{
Gate::authorize('update', $account);

return Inertia::render('Accounts/AccountEdit', compact('account'));
return $this->inertiaRender('Accounts/AccountEdit', compact('account'));
}

public function update(Request $request, Account $account)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

namespace App\Http\Controllers\Manage\Accounts;

use App\Domains\Manage\RendersManageApp;
use App\Http\Controllers\WebController;
use App\Models\Account;
use App\Models\Group;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Inertia\Inertia;

class AccountGroupController extends WebController
{
use RendersManageApp;

public function index(Request $request, Account $account)
{
Gate::authorize('viewAny', Account::class);

$groups = Group::where('is_default', false)->get();
$accountGroupIds = $account->groups->pluck(Group::primaryKey());

return Inertia::render('Accounts/AccountGroupSelect', [
return $this->inertiaRender('Accounts/AccountGroupSelect', [
'groups' => $groups,
'account_group_ids' => $accountGroupIds ?? [],
'account_id' => $account->getKey(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID;
use App\Core\Domains\MinecraftUUID\Rules\MinecraftUUIDRule;
use App\Domains\Manage\RendersManageApp;
use App\Http\Controllers\WebController;
use App\Models\Account;
use App\Models\Group;
use App\Models\MinecraftPlayer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Inertia\Inertia;

class AccountPlayerController extends WebController
{
use RendersManageApp;

public function create(Request $request, Account $account)
{
Gate::authorize('update', $account);

return Inertia::render('Accounts/AccountPlayerSelect', [
return $this->inertiaRender('Accounts/AccountPlayerSelect', [
'account_id' => $account->getKey(),
]);
}
Expand Down
10 changes: 6 additions & 4 deletions app/Http/Controllers/Manage/Badges/BadgeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

namespace App\Http\Controllers\Manage\Badges;

use App\Domains\Manage\RendersManageApp;
use App\Http\Controllers\WebController;
use App\Models\Badge;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Inertia\Inertia;

class BadgeController extends WebController
{
use RendersManageApp;

public function index(Request $request)
{
Gate::authorize('viewAny', Badge::class);
Expand All @@ -20,14 +22,14 @@ public function index(Request $request)
if ($request->wantsJson()) {
return $badges;
}
return Inertia::render('Badges/BadgeList', compact('badges'));
return $this->inertiaRender('Badges/BadgeList', compact('badges'));
}

public function create(Request $request)
{
Gate::authorize('create', Badge::class);

return Inertia::render('Badges/BadgeCreate');
return $this->inertiaRender('Badges/BadgeCreate');
}

public function store(Request $request)
Expand Down Expand Up @@ -57,7 +59,7 @@ public function edit(Badge $badge)
{
Gate::authorize('update', $badge);

return Inertia::render('Badges/BadgeEdit', compact('badge'));
return $this->inertiaRender('Badges/BadgeEdit', compact('badge'));
}

public function update(Request $request, Badge $badge)
Expand Down
10 changes: 6 additions & 4 deletions app/Http/Controllers/Manage/Bans/GameIPBanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID;
use App\Core\Domains\MinecraftUUID\Rules\MinecraftUUIDRule;
use App\Domains\Manage\RendersManageApp;
use App\Domains\MinecraftEventBus\Events\IpAddressBanned;
use App\Http\Controllers\WebController;
use App\Models\GameIPBan;
use App\Models\MinecraftPlayer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Inertia\Inertia;

class GameIPBanController extends WebController
{
use RendersManageApp;

public function index(Request $request)
{
Gate::authorize('viewAny', GameIPBan::class);
Expand All @@ -25,14 +27,14 @@ public function index(Request $request)
if (request()->wantsJson()) {
return $bans;
}
return Inertia::render('IPBans/IPBanList', compact('bans'));
return $this->inertiaRender('IPBans/IPBanList', compact('bans'));
}

public function create(Request $request)
{
Gate::authorize('create', GameIPBan::class);

return Inertia::render('IPBans/IPBanCreate');
return $this->inertiaRender('IPBans/IPBanCreate');
}

public function store(Request $request)
Expand Down Expand Up @@ -65,7 +67,7 @@ public function edit(GameIPBan $ipBan)

$ipBan->load('bannerPlayer');

return Inertia::render('IPBans/IPBanEdit', [
return $this->inertiaRender('IPBans/IPBanEdit', [
'ban' => $ipBan,
]);
}
Expand Down
9 changes: 6 additions & 3 deletions app/Http/Controllers/Manage/Bans/GamePlayerBanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Core\Domains\MinecraftUUID\Data\MinecraftUUID;
use App\Core\Domains\MinecraftUUID\Rules\MinecraftUUIDRule;
use App\Domains\Bans\Data\UnbanType;
use App\Domains\Manage\RendersManageApp;
use App\Domains\MinecraftEventBus\Events\MinecraftUuidBanned;
use App\Http\Controllers\WebController;
use App\Models\GamePlayerBan;
Expand All @@ -16,6 +17,8 @@

class GamePlayerBanController extends WebController
{
use RendersManageApp;

public function index(Request $request)
{
Gate::authorize('viewAny', GamePlayerBan::class);
Expand All @@ -27,7 +30,7 @@ public function index(Request $request)
if (request()->wantsJson()) {
return $bans;
}
return Inertia::render('PlayerBans/PlayerBanList', compact('bans'));
return $this->inertiaRender('PlayerBans/PlayerBanList', compact('bans'));
}

public function create(Request $request)
Expand All @@ -37,7 +40,7 @@ public function create(Request $request)
$account = $request->user();
$account->load('minecraftAccount');

return Inertia::render('PlayerBans/PlayerBanCreate', [
return $this->inertiaRender('PlayerBans/PlayerBanCreate', [
'account' => $account,
]);
}
Expand Down Expand Up @@ -84,7 +87,7 @@ public function edit(GamePlayerBan $playerBan)

$playerBan->load('bannedPlayer', 'bannerPlayer', 'unbannerPlayer');

return Inertia::render('PlayerBans/PlayerBanEdit', [
return $this->inertiaRender('PlayerBans/PlayerBanEdit', [
'ban' => $playerBan,
]);
}
Expand Down
11 changes: 7 additions & 4 deletions app/Http/Controllers/Manage/Donations/DonationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Manage\Donations;

use App\Domains\Manage\RendersManageApp;
use App\Http\Controllers\WebController;
use App\Models\Donation;
use Illuminate\Http\Request;
Expand All @@ -10,6 +11,8 @@

class DonationController extends WebController
{
use RendersManageApp;

public function index(Request $request)
{
Gate::authorize('viewAny', Donation::class);
Expand All @@ -21,7 +24,7 @@ public function index(Request $request)
if (request()->wantsJson()) {
return $donations;
}
return Inertia::render(
return $this->inertiaRender(
'Donations/DonationList',
compact('donations'),
);
Expand All @@ -33,7 +36,7 @@ public function show(Donation $donation)

$donation->load('perks', 'perks.account');

return Inertia::render(
return $this->inertiaRender(
'Donations/DonationShow',
compact('donation'),
);
Expand All @@ -43,7 +46,7 @@ public function create(Request $request)
{
Gate::authorize('create', Donation::class);

return Inertia::render('Donations/DonationCreate');
return $this->inertiaRender('Donations/DonationCreate');
}

public function store(Request $request)
Expand All @@ -66,7 +69,7 @@ public function edit(Donation $donation)
{
Gate::authorize('update', $donation);

return Inertia::render(
return $this->inertiaRender(
'Donations/DonationEdit',
compact('donation'),
);
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/Manage/Groups/GroupAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

namespace App\Http\Controllers\Manage\Groups;

use App\Domains\Manage\RendersManageApp;
use App\Http\Controllers\WebController;
use App\Models\Account;
use App\Models\Group;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Inertia\Inertia;

class GroupAccountController extends WebController
{
use RendersManageApp;

public function index(Request $request, Group $group)
{
Gate::authorize('view', $group);
Expand All @@ -26,7 +28,7 @@ public function index(Request $request, Group $group)
if ($request->wantsJson()) {
return $accounts;
}
return Inertia::render(
return $this->inertiaRender(
'Groups/GroupAccountList',
compact('accounts', 'group'),
);
Expand Down
Loading

0 comments on commit 9dba923

Please sign in to comment.