From 93d869cf8cca8877c591992b88e2b7bd8601ae18 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 30 May 2026 01:57:35 +0300 Subject: [PATCH] Fix: lightbox, profile stats, toast, rating UX --- app/Http/Controllers/UserController.php | 22 ++-- resources/views/games/show.blade.php | 138 +++++++++++++++++++----- resources/views/layouts/app.blade.php | 1 + resources/views/users/show.blade.php | 67 ++++++++++-- 4 files changed, 192 insertions(+), 36 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 7d8ba59..bdc7124 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -16,14 +16,24 @@ class UserController extends Controller 'total' => $user->library()->count(), ]; - $recentlyPlayed = $user->library() - ->with('game') - ->where('status', 'played') - ->latest('updated_at') - ->limit(6) + $genreStats = \DB::table('genres') + ->select('genres.id', 'genres.name', \DB::raw('COUNT(*) as count')) + ->join('game_genre', 'genres.id', '=', 'game_genre.genre_id') + ->join('user_games', 'game_genre.game_id', '=', 'user_games.game_id') + ->where('user_games.user_id', $user->id) + ->whereIn('user_games.status', ['played', 'playing']) + ->groupBy('genres.id', 'genres.name') + ->orderByDesc('count') + ->limit(5) ->get(); - return view('users.show', compact('user', 'stats', 'recentlyPlayed')); + $allGames = $user->library() + ->with('game') + ->latest('updated_at') + ->limit(12) + ->get(); + + return view('users.show', compact('user', 'stats', 'genreStats', 'allGames')); } public function library(User $user) diff --git a/resources/views/games/show.blade.php b/resources/views/games/show.blade.php index 308b356..647452a 100644 --- a/resources/views/games/show.blade.php +++ b/resources/views/games/show.blade.php @@ -119,25 +119,49 @@ @else @auth -
-
- -
- @foreach(['playing' => 'Playing', 'played' => 'Played', 'want_to_play' => 'Want to Play', 'on_hold' => 'On Hold', 'dropped' => 'Dropped'] as $s => $label) - - @endforeach +
+ @foreach(['playing' => 'Playing', 'played' => 'Played', 'want_to_play' => 'Want to Play', 'on_hold' => 'On Hold', 'dropped' => 'Dropped'] as $s => $label) + + @endforeach +
+ + {{-- Step 2: optional rating + save --}} +
+ Adding as +
+ + + /10 +
+ + +
@else @endauth @endif + + {{-- Toast notification --}} + {{-- Companies --}} @@ -177,15 +208,66 @@ {{-- Screenshots --}} @if($game->screenshots->isNotEmpty()) -
+

Screenshots

+ + {{-- Lightbox overlay --}} +
@endif @@ -233,6 +315,9 @@ function libraryWidget(gameId, initialStatus, initialRating) { gameId, status: initialStatus, rating: initialRating, + toast: null, + pendingStatus: null, + pendingRating: null, statusLabel(s) { const labels = { @@ -245,7 +330,12 @@ function libraryWidget(gameId, initialStatus, initialRating) { return labels[s] || 'In Library'; }, - async addToLibrary(status) { + showToast(message) { + this.toast = message; + setTimeout(() => { this.toast = null; }, 2500); + }, + + async addToLibraryWithRating() { const res = await fetch('/library', { method: 'POST', headers: { @@ -253,11 +343,11 @@ function libraryWidget(gameId, initialStatus, initialRating) { 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content, 'Accept': 'application/json', }, - body: JSON.stringify({ game_id: this.gameId, status }), + body: JSON.stringify({ game_id: this.gameId, status: this.pendingStatus, rating: this.pendingRating || null }), }); if (res.ok) { - this.status = status; - window.location.reload(); + this.showToast('Added to library!'); + setTimeout(() => window.location.reload(), 1000); } }, diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index f4d69ae..9ea4d6b 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -77,6 +77,7 @@ @if(auth()->user()->username) Profile My Library + My Lists @endif Settings
diff --git a/resources/views/users/show.blade.php b/resources/views/users/show.blade.php index 04ad235..7a4871f 100644 --- a/resources/views/users/show.blade.php +++ b/resources/views/users/show.blade.php @@ -53,18 +53,73 @@
- {{-- Recently Played --}} - @if($recentlyPlayed->isNotEmpty()) + {{-- Top Genres --}} + @if($genreStats->isNotEmpty()) +
+

Top Genres

+
+ @foreach($genreStats as $genre) + + {{ $genre->name }} + {{ $genre->count }} + + @endforeach +
+
+ @endif + + {{-- Recent Library --}} + @if($allGames->isNotEmpty())
-

Recently Played

+
+

Recent Library

+ + View all → + +
- @foreach($recentlyPlayed as $entry) - + @foreach($allGames as $entry) + @php + $statusColors = [ + 'playing' => 'bg-green-600', + 'played' => 'bg-blue-600', + 'want_to_play' => 'bg-yellow-600', + 'on_hold' => 'bg-orange-600', + 'dropped' => 'bg-red-700', + ]; + $statusLabels = [ + 'playing' => 'Playing', + 'played' => 'Played', + 'want_to_play' => 'Want to Play', + 'on_hold' => 'On Hold', + 'dropped' => 'Dropped', + ]; + @endphp +
+ + + {{ $statusLabels[$entry->status] ?? $entry->status }} + +
@endforeach
@else -

No games tracked yet.

+ {{-- Empty state --}} +
+
+ + + +
+

No games tracked yet

+

Start building your game library!

+ + Browse Games + +
@endif