17 - Share scenario as Inertia shared data
This commit is contained in:
parent
ac3e6d2ff9
commit
a7f9799391
2 changed files with 14 additions and 0 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Http\Resources\ScenarioResource;
|
||||||
|
use App\Models\Scenario;
|
||||||
use Illuminate\Foundation\Inspiring;
|
use Illuminate\Foundation\Inspiring;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Inertia\Middleware;
|
use Inertia\Middleware;
|
||||||
|
|
@ -46,6 +48,7 @@ public function share(Request $request): array
|
||||||
'user' => $request->user(),
|
'user' => $request->user(),
|
||||||
],
|
],
|
||||||
'sidebarOpen' => ! $request->hasCookie('sidebar_state') || $request->cookie('sidebar_state') === 'true',
|
'sidebarOpen' => ! $request->hasCookie('sidebar_state') || $request->cookie('sidebar_state') === 'true',
|
||||||
|
'scenario' => fn () => ($scenario = Scenario::first()) ? new ScenarioResource($scenario) : null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
resources/js/types/index.d.ts
vendored
11
resources/js/types/index.d.ts
vendored
|
|
@ -22,10 +22,21 @@ export interface NavItem {
|
||||||
isActive?: boolean;
|
isActive?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Scenario {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string | null;
|
||||||
|
distribution_mode: 'even' | 'priority';
|
||||||
|
distribution_mode_label: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface SharedData {
|
export interface SharedData {
|
||||||
name: string;
|
name: string;
|
||||||
quote: { message: string; author: string };
|
quote: { message: string; author: string };
|
||||||
auth: Auth;
|
auth: Auth;
|
||||||
|
scenario: Scenario | null;
|
||||||
sidebarOpen: boolean;
|
sidebarOpen: boolean;
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue