diff --git a/app/Http/Controllers/ModController.php b/app/Http/Controllers/ModController.php index acbf826..86b89ee 100644 --- a/app/Http/Controllers/ModController.php +++ b/app/Http/Controllers/ModController.php @@ -45,7 +45,7 @@ class ModController extends Controller $this->authorize('view', $mod); - $latestVersion = $mod->versions->sortByDesc('created_at')->first(); + $latestVersion = $mod->versions->sortByDesc('version')->first(); return view('mod.show', compact(['mod', 'latestVersion'])); } diff --git a/app/Http/Resources/Api/V0/ModResource.php b/app/Http/Resources/Api/V0/ModResource.php index d02762d..23ed9cc 100644 --- a/app/Http/Resources/Api/V0/ModResource.php +++ b/app/Http/Resources/Api/V0/ModResource.php @@ -80,10 +80,7 @@ class ModResource extends JsonResource ->values() ), 'links' => [ - 'self' => route('mod.show', [ - 'mod' => $this->id, - 'slug' => $this->slug, - ]), + 'self' => $this->detailUrl(), ], ]; } diff --git a/app/Jobs/ImportHubData.php b/app/Jobs/ImportHubData.php index 74ac2b1..bac52eb 100644 --- a/app/Jobs/ImportHubData.php +++ b/app/Jobs/ImportHubData.php @@ -633,7 +633,7 @@ class ImportHubData implements ShouldBeUnique, ShouldQueue 'users' => $modAuthors, 'name' => $modContent?->subject ?? '', 'slug' => Str::slug($modContent?->subject ?? ''), - 'teaser' => Str::limit($modContent?->teaser ?? ''), + 'teaser' => Str::limit($modContent?->teaser ?? '', 255), 'description' => $this->cleanHubContent($modContent?->message ?? ''), 'thumbnail' => $this->fetchModThumbnail($curl, $mod->fileID, $mod->iconHash, $mod->iconExtension), 'license_id' => License::whereHubId($mod->licenseID)->value('id'), diff --git a/app/Models/Mod.php b/app/Models/Mod.php index 193cc17..2388390 100644 --- a/app/Models/Mod.php +++ b/app/Models/Mod.php @@ -154,6 +154,14 @@ class Mod extends Model return $filters->apply($builder); } + /** + * Build the URL to the mod's detail page. + */ + public function detailUrl(): string + { + return route('mod.show', [$this->id, $this->slug]); + } + /** * The attributes that should be cast to native types. */ diff --git a/resources/views/components/mod-list.blade.php b/resources/views/components/mod-list.blade.php index ca5ed34..956f6c2 100644 --- a/resources/views/components/mod-list.blade.php +++ b/resources/views/components/mod-list.blade.php @@ -2,6 +2,8 @@
@foreach ($mods as $mod) - + @if ($mod->{$versionScope}) + + @endif @endforeach
diff --git a/resources/views/mod/show.blade.php b/resources/views/mod/show.blade.php index ef5ab29..e7e8ae2 100644 --- a/resources/views/mod/show.blade.php +++ b/resources/views/mod/show.blade.php @@ -43,16 +43,21 @@

+ + {{-- Mod teaser --}} + @if ($mod->teaser) +

{{ $mod->teaser }}

+ @endif + {{-- Mobile Download Button --}} + + + + {{-- Tabs --}}
- {{-- Mobile Download Button --}} - - - - {{-- Mobile Dropdown --}}
@@ -84,7 +89,7 @@ {{-- Mod Description --}}
- {{-- The description below is safe to write directly because it has been run though HTMLPurifier during the import process. --}} + {{-- The description below is safe to write directly because it has been run though HTMLPurifier. --}} {!! Str::markdown($mod->description) !!}
@@ -114,7 +119,7 @@ {{ __('Dependencies:') }} @foreach ($version->dependencies as $dependency) @if ($dependency->resolvedVersion?->mod) - + {{ $dependency->resolvedVersion->mod->name }} ({{ $dependency->resolvedVersion->version }}) @if (!$loop->last), @endif @endif @@ -184,7 +189,7 @@

{{ __('Latest Version Dependencies') }}

@foreach ($latestVersion->dependencies as $dependency) - + {{ $dependency->resolvedVersion->mod->name }} ({{ $dependency->resolvedVersion->version }})
@endforeach diff --git a/tests/Feature/ModTest.php b/tests/Feature/ModTest.php new file mode 100644 index 0000000..a76dff6 --- /dev/null +++ b/tests/Feature/ModTest.php @@ -0,0 +1,42 @@ +create(); + + // Create 5 mod versions with specified versions + $versions = [ + '1.0.0', + '1.1.0', + '1.2.0', + '2.0.0', + '2.1.0', + ]; + + // get the highest version in the array + $latestVersion = max($versions); + + foreach ($versions as $version) { + ModVersion::factory()->create([ + 'mod_id' => $mod->id, + 'version' => $version, + ]); + } + + // Make a request to the mod's detail URL + $response = $this->get($mod->detailUrl()); + + $this->assertEquals('2.1.0', $latestVersion); + + // Assert the latest version is next to the mod's name + $response->assertSeeInOrder(explode(' ', "$mod->name $latestVersion")); + + // Assert the latest version is in the latest download button + $response->assertSeeText(__('Download Latest Version')." ($latestVersion)"); +});