From 0a271ff03e53680a3a8a03950ddfb19c14ed257f Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Mon, 9 Sep 2024 16:20:54 -0400 Subject: [PATCH 1/5] add link to sections --- app/View/Components/ModListSection.php | 3 +++ resources/views/components/mod-list-section-partial.blade.php | 4 ++-- resources/views/components/mod-list-section.blade.php | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/View/Components/ModListSection.php b/app/View/Components/ModListSection.php index d08350e..f9c257c 100644 --- a/app/View/Components/ModListSection.php +++ b/app/View/Components/ModListSection.php @@ -88,16 +88,19 @@ class ModListSection extends Component 'title' => __('Featured Mods'), 'mods' => $this->modsFeatured, 'versionScope' => 'latestVersion', + 'link' => '/mods?featured=only', ], [ 'title' => __('Newest Mods'), 'mods' => $this->modsLatest, 'versionScope' => 'latestVersion', + 'link' => '/mods', ], [ 'title' => __('Recently Updated Mods'), 'mods' => $this->modsUpdated, 'versionScope' => 'lastUpdatedVersion', + 'link' => '/mods?order=updated', ], ]; } diff --git a/resources/views/components/mod-list-section-partial.blade.php b/resources/views/components/mod-list-section-partial.blade.php index efbbc7a..79c68c9 100644 --- a/resources/views/components/mod-list-section-partial.blade.php +++ b/resources/views/components/mod-list-section-partial.blade.php @@ -1,10 +1,10 @@ -@props(['mods', 'versionScope', 'title']) +@props(['mods', 'versionScope', 'title', 'link'])
{{-- TODO: The button-link should be dynamic based on the versionScope. Eg. Featured `View All` button should take the user to the mods page with the `featured` query parameter set. --}} - +
diff --git a/resources/views/components/mod-list-section.blade.php b/resources/views/components/mod-list-section.blade.php index a7528cd..15a0daa 100644 --- a/resources/views/components/mod-list-section.blade.php +++ b/resources/views/components/mod-list-section.blade.php @@ -3,5 +3,6 @@ 'title' => $section['title'], 'mods' => $section['mods'], 'versionScope' => $section['versionScope'], + 'link' => $section['link'] ]) @endforeach From ed2091fb23647487808b9419dc29f23992cd9355 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Tue, 10 Sep 2024 09:10:16 -0400 Subject: [PATCH 2/5] remove session properties --- app/Livewire/Mod/Index.php | 5 ----- .../views/components/mod-list-section-partial.blade.php | 4 ---- 2 files changed, 9 deletions(-) diff --git a/app/Livewire/Mod/Index.php b/app/Livewire/Mod/Index.php index 5760c14..602a0d6 100644 --- a/app/Livewire/Mod/Index.php +++ b/app/Livewire/Mod/Index.php @@ -8,7 +8,6 @@ use Illuminate\Contracts\View\View; use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Facades\Cache; use Livewire\Attributes\Computed; -use Livewire\Attributes\Session; use Livewire\Attributes\Url; use Livewire\Component; use Livewire\WithPagination; @@ -21,28 +20,24 @@ class Index extends Component * The search query value. */ #[Url] - #[Session] public string $query = ''; /** * The sort order value. */ #[Url] - #[Session] public string $order = 'created'; /** * The SPT versions filter value. */ #[Url] - #[Session] public array $sptVersions = []; /** * The featured filter value. */ #[Url] - #[Session] public string $featured = 'include'; /** diff --git a/resources/views/components/mod-list-section-partial.blade.php b/resources/views/components/mod-list-section-partial.blade.php index 79c68c9..21dc3f9 100644 --- a/resources/views/components/mod-list-section-partial.blade.php +++ b/resources/views/components/mod-list-section-partial.blade.php @@ -1,10 +1,6 @@ @props(['mods', 'versionScope', 'title', 'link'])
- {{-- - TODO: The button-link should be dynamic based on the versionScope. Eg. Featured `View All` button should take - the user to the mods page with the `featured` query parameter set. - --}}
From 8211731c324c3d8ead148e1ddda42c34d7b18f4f Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Tue, 10 Sep 2024 09:20:53 -0400 Subject: [PATCH 3/5] remove clear filters call --- app/Livewire/Mod/Index.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Livewire/Mod/Index.php b/app/Livewire/Mod/Index.php index 602a0d6..1e0a7ad 100644 --- a/app/Livewire/Mod/Index.php +++ b/app/Livewire/Mod/Index.php @@ -97,9 +97,6 @@ class Index extends Component $this->query = ''; $this->sptVersions = $this->getLatestMinorVersions()->pluck('version')->toArray(); $this->featured = 'include'; - - // Clear local storage - $this->dispatch('clear-filters'); } /** From b5516d3a7ee52b014c534cc247804dc37bbe0fb3 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Wed, 11 Sep 2024 14:20:39 -0400 Subject: [PATCH 4/5] update list stats --- .../views/components/mod-list-stats.blade.php | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/resources/views/components/mod-list-stats.blade.php b/resources/views/components/mod-list-stats.blade.php index 286fb3b..ab2cdd2 100644 --- a/resources/views/components/mod-list-stats.blade.php +++ b/resources/views/components/mod-list-stats.blade.php @@ -1,13 +1,32 @@

class(['text-slate-700 dark:text-gray-300 text-sm']) }}> - {{ Number::downloads($mod->downloads) }} downloads - @if(!is_null($mod->created_at)) - - — Created - - - @elseif(!is_null($modVersion->updated_at)) - — Updated {{ $modVersion->updated_at->diffForHumans() }} - @endif +

+
+
+ + + + + @if(!is_null($mod->updated_at)) + + @elseif(!is_null($mod->created_at)) + + @else + N/A + @endif + +
+
+
+ + {{ Number::downloads($mod->downloads) }} + + + + +
+

From 1874dab621732513c0235509ef101fb33ef3e2df Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Wed, 11 Sep 2024 14:41:31 -0400 Subject: [PATCH 5/5] display seeder progress --- database/seeders/DatabaseSeeder.php | 104 +++++++++++++++++++++------- 1 file changed, 79 insertions(+), 25 deletions(-) diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 1cfedfb..6becca0 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -11,6 +11,8 @@ use App\Models\User; use App\Models\UserRole; use Illuminate\Database\Seeder; +use function Laravel\Prompts\progress; + class DatabaseSeeder extends Seeder { /** @@ -18,46 +20,98 @@ class DatabaseSeeder extends Seeder */ public function run(): void { + // how many of each "thing" to make during seeding + $userCount = 100; + $modCount = 300; + $modVersionCount = 3000; + // Create a few SPT versions. $spt_versions = SptVersion::factory(30)->create(); // Create some code licenses. $licenses = License::factory(10)->create(); - // Add 5 administrators. - $administrator = UserRole::factory()->administrator()->create(); - User::factory()->for($administrator, 'role')->create([ + // Add administrators. + $administratorRole = UserRole::factory()->administrator()->create(); + $testAccount = User::factory()->for($administratorRole, 'role')->create([ 'email' => 'test@example.com', ]); - User::factory(4)->for($administrator, 'role')->create(); - // Add 10 moderators. - $moderator = UserRole::factory()->moderator()->create(); - User::factory(5)->for($moderator, 'role')->create(); + $this->command->outputComponents()->info("test account created: $testAccount->email"); - // Add 100 users. - $users = User::factory(100)->create(); + User::factory(4)->for($administratorRole, 'role')->create(); - // Add 300 mods, assigning them to the users we just created. - $allUsers = $users->merge([$administrator, $moderator]); - $mods = Mod::factory(300)->recycle([$licenses])->create(); - foreach ($mods as $mod) { - $userIds = $allUsers->random(rand(1, 3))->pluck('id')->toArray(); - $mod->users()->attach($userIds); - } + // Add moderators. + $moderatorRole = UserRole::factory()->moderator()->create(); + User::factory(5)->for($moderatorRole, 'role')->create(); - // Add 3000 mod versions, assigning them to the mods we just created. - $modVersions = ModVersion::factory(3000)->recycle([$mods, $spt_versions])->create(); + // Add users + progress( + label: 'adding users...', + steps: $userCount, + callback: fn () => User::factory()->create() + ); + + // get all users + $allUsers = User::all(); + + // Add user follows + progress( + label: 'adding user follows ...', + steps: $allUsers, + callback: function ($user) use ($allUsers) { + $hasFollowers = rand(0, 100) < 70; // 70% chance to have followers + $isFollowing = rand(0, 100) < 70; // 70% chance to be following other users + + if ($hasFollowers) { + $followers = $allUsers->random(rand(1, 10))->pluck('id')->toArray(); + $user->followers()->attach($followers); + } + + if ($isFollowing) { + $following = $allUsers->random(rand(1, 10))->pluck('id')->toArray(); + $user->following()->attach($following); + } + }); + + $mods = collect(progress( + label: 'adding mods...', + steps: $modCount, + callback: fn () => Mod::factory()->recycle([$licenses])->create() + )); + + // attach users to mods + progress( + label: 'attaching mod users ...', + steps: $mods, + callback: function ($mod) use ($allUsers) { + $userIds = $allUsers->random(rand(1, 3))->pluck('id')->toArray(); + $mod->users()->attach($userIds); + } + ); + + // Add mod versions, assigning them to the mods we just created. + $modVersions = collect(progress( + label: 'adding mods versions ...', + steps: $modVersionCount, + callback: fn () => ModVersion::factory()->recycle([$mods, $spt_versions])->create() + )); // Add ModDependencies to a subset of ModVersions. - foreach ($modVersions as $modVersion) { - $hasDependencies = rand(0, 100) < 30; // 30% chance to have dependencies - if ($hasDependencies) { - $dependencyMods = $mods->random(rand(1, 3)); // 1 to 3 dependencies - foreach ($dependencyMods as $dependencyMod) { - ModDependency::factory()->recycle([$modVersion, $dependencyMod])->create(); + progress( + label: 'adding mods dependencies ...', + steps: $modVersions, + callback: function ($modVersion) use ($mods) { + $hasDependencies = rand(0, 100) < 30; // 30% chance to have dependencies + if ($hasDependencies) { + $dependencyMods = $mods->random(rand(1, 3)); // 1 to 3 dependencies + foreach ($dependencyMods as $dependencyMod) { + ModDependency::factory()->recycle([$modVersion, $dependencyMod])->create(); + } } } - } + ); + + $this->command->outputComponents()->success('Database seeded'); } }