fixed browse and tailwindcss style

This commit is contained in:
2026-02-15 11:01:19 +01:00
parent d114472823
commit 7734e53d87
16 changed files with 341 additions and 200 deletions

View File

@@ -24,8 +24,9 @@ class BrowseController extends Controller
public function index(Request $request)
{
$perPage = min(max((int) $request->get('per_page', 24), 1), 100);
$sort = (string) $request->get('sort', 'latest');
$paginator = $this->service->browsePublicArtworks($perPage);
$paginator = $this->service->browsePublicArtworks($perPage, $sort);
return ArtworkListResource::collection($paginator);
}
@@ -37,9 +38,10 @@ class BrowseController extends Controller
public function byContentType(Request $request, string $contentTypeSlug)
{
$perPage = min(max((int) $request->get('per_page', 24), 1), 100);
$sort = (string) $request->get('sort', 'latest');
try {
$paginator = $this->service->getArtworksByContentType($contentTypeSlug, $perPage);
$paginator = $this->service->getArtworksByContentType($contentTypeSlug, $perPage, $sort);
} catch (ModelNotFoundException $e) {
abort(404);
}
@@ -58,13 +60,14 @@ class BrowseController extends Controller
public function byCategoryPath(Request $request, string $contentTypeSlug, string $categoryPath)
{
$perPage = min(max((int) $request->get('per_page', 24), 1), 100);
$sort = (string) $request->get('sort', 'latest');
$slugs = array_merge([
strtolower($contentTypeSlug),
], array_values(array_filter(explode('/', trim($categoryPath, '/')))));
try {
$paginator = $this->service->getArtworksByCategoryPath($slugs, $perPage);
$paginator = $this->service->getArtworksByCategoryPath($slugs, $perPage, $sort);
} catch (ModelNotFoundException $e) {
abort(404);
}

View File

@@ -4,13 +4,15 @@ namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\ContentType;
use App\Models\Artwork;
use App\Services\ArtworkService;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
class CategoryPageController extends Controller
{
public function __construct(private ArtworkService $artworkService)
{
}
public function show(Request $request, string $contentTypeSlug, ?string $categoryPath = null)
{
$contentType = ContentType::where('slug', strtolower($contentTypeSlug))->first();
@@ -18,6 +20,8 @@ class CategoryPageController extends Controller
abort(404);
}
$sort = (string) $request->get('sort', 'latest');
if ($categoryPath === null || $categoryPath === '') {
// No category path: show content-type landing page (e.g., /wallpapers)
@@ -27,20 +31,7 @@ class CategoryPageController extends Controller
// Load artworks for this content type (show gallery on the root page)
$perPage = 40;
$artworks = Artwork::whereHas('categories', function ($q) use ($contentType) {
$q->where('categories.content_type_id', $contentType->id);
})
->published()->public()
->with([
'user:id,name',
'categories' => function ($q) {
$q->select('categories.id', 'categories.content_type_id', 'categories.parent_id', 'categories.name', 'categories.slug', 'categories.sort_order')
->with(['parent:id,parent_id,content_type_id,name,slug', 'contentType:id,slug,name']);
},
])
->orderBy('published_at', 'desc')
->paginate($perPage)
->withQueryString();
$artworks = $this->artworkService->getArtworksByContentType($contentType->slug, $perPage, $sort);
return view('legacy.content-type', compact(
'contentType',
@@ -88,10 +79,9 @@ class CategoryPageController extends Controller
// Load artworks via ArtworkService to support arbitrary-depth category paths
$perPage = 40;
try {
$service = app(ArtworkService::class);
// service expects an array with contentType slug first, then category slugs
$pathSlugs = array_merge([strtolower($contentTypeSlug)], $slugs);
$artworks = $service->getArtworksByCategoryPath($pathSlugs, $perPage);
$artworks = $this->artworkService->getArtworksByCategoryPath($pathSlugs, $perPage, $sort);
} catch (\Throwable $e) {
abort(404);
}

View File

@@ -4,12 +4,12 @@ namespace App\Http\Controllers\Legacy;
use App\Http\Controllers\Controller;
use App\Models\Artwork;
use App\Models\ContentType;
use App\Services\ArtworkService;
use Illuminate\Http\Request;
use Illuminate\Pagination\CursorPaginator;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
class BrowseController extends Controller
{
@@ -27,18 +27,22 @@ class BrowseController extends Controller
$page_meta_keywords = 'photography, wallpapers, skins, stock, browse, social, community, artist, picture, photo';
$perPage = (int) $request->get('per_page', 24);
$sort = (string) $request->get('sort', 'latest');
$categoryPath = trim((string) $request->query('category', ''), '/');
// Canonical browse routes are slug-based (/photography, /wallpapers, /skins, /other, /{type}/{path}).
// Prevent duplicate query-driven browse URLs.
$legacyCategory = trim((string) $request->query('category', ''), '/');
if ($legacyCategory !== '') {
return redirect('/' . strtolower($legacyCategory), 301);
}
$legacyContentType = trim((string) $request->query('content_type', ''), '/');
if ($legacyContentType !== '') {
return redirect('/' . strtolower($legacyContentType), 301);
}
try {
if ($categoryPath !== '') {
$slugs = array_values(array_filter(explode('/', $categoryPath)));
/** @var CursorPaginator $artworks */
$artworks = $this->artworks->getArtworksByCategoryPath($slugs, $perPage);
} else {
/** @var CursorPaginator $artworks */
$artworks = $this->artworks->browsePublicArtworks($perPage);
}
/** @var CursorPaginator $artworks */
$artworks = $this->artworks->browsePublicArtworks($perPage, $sort);
} catch (ModelNotFoundException $e) {
abort(404);
}
@@ -46,7 +50,6 @@ class BrowseController extends Controller
if (count($artworks) === 0) {
Log::warning('browse.missing_artworks', [
'url' => $request->fullUrl(),
'category_path' => $categoryPath ?: null,
]);
abort(410);
}
@@ -54,7 +57,16 @@ class BrowseController extends Controller
// Shape data for the legacy Blade while using authoritative tables only.
$artworks->getCollection()->transform(fn (Artwork $artwork) => $this->mapArtwork($artwork));
return view('legacy.browse', compact('page_title', 'page_meta_description', 'page_meta_keywords', 'artworks'));
$rootCategories = ContentType::orderBy('id')
->get(['name', 'slug'])
->map(fn (ContentType $type) => (object) [
'name' => $type->name,
'url' => '/' . strtolower($type->slug),
]);
$page_canonical = url('/browse');
return view('legacy.browse', compact('page_title', 'page_meta_description', 'page_meta_keywords', 'page_canonical', 'artworks', 'rootCategories'));
}
private function mapArtwork(Artwork $artwork): object

View File

@@ -49,9 +49,10 @@ class CategoryController extends Controller
$slugs = array_merge([$contentTypeSlug], $parts);
$perPage = (int) $request->get('per_page', 40);
$sort = (string) $request->get('sort', 'latest');
try {
$artworks = $this->artworkService->getArtworksByCategoryPath($slugs, $perPage);
$artworks = $this->artworkService->getArtworksByCategoryPath($slugs, $perPage, $sort);
} catch (ModelNotFoundException $e) {
abort(404);
}

View File

@@ -53,24 +53,11 @@ class PhotographyController extends Controller
$tidy = $category->description ?? ($ct->description ?? null);
$perPage = 40;
$sort = (string) $request->get('sort', 'latest');
// Load artworks for the requested content type using standard pagination
try {
$artQuery = \App\Models\Artwork::public()
->published()
->whereHas('categories', function ($q) use ($ct) {
$q->where('categories.content_type_id', $ct->id);
})
->with([
'user:id,name',
'categories' => function ($q) {
$q->select('categories.id', 'categories.content_type_id', 'categories.parent_id', 'categories.name', 'categories.slug', 'categories.sort_order')
->with(['parent:id,parent_id,content_type_id,name,slug', 'contentType:id,slug,name']);
},
])
->orderByDesc('published_at');
$artworks = $artQuery->paginate($perPage)->withQueryString();
$artworks = $this->artworks->getArtworksByContentType($contentSlug, $perPage, $sort);
} catch (\Throwable $e) {
// Return an empty paginator so views using ->links() / ->firstItem() work
$artworks = new \Illuminate\Pagination\LengthAwarePaginator([], 0, $perPage, 1, [

View File

@@ -8,6 +8,7 @@ use App\Models\ArtworkFeature;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Contracts\Pagination\CursorPaginator;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Cache;
@@ -23,6 +24,29 @@ class ArtworkService
{
protected int $cacheTtl = 3600; // seconds
/**
* Shared browse query used by /browse, content-type pages, and category pages.
*/
private function browseQuery(string $sort = 'latest'): Builder
{
$query = Artwork::public()
->published()
->with([
'user:id,name',
'categories' => function ($q) {
$q->select('categories.id', 'categories.content_type_id', 'categories.parent_id', 'categories.name', 'categories.slug', 'categories.sort_order')
->with(['parent:id,parent_id,content_type_id,name,slug', 'contentType:id,slug,name']);
},
]);
$normalizedSort = strtolower(trim($sort));
if ($normalizedSort === 'oldest') {
return $query->orderBy('published_at', 'asc');
}
return $query->orderByDesc('published_at');
}
/**
* Fetch a single public artwork by slug.
* Applies visibility rules (public + approved + not-deleted).
@@ -115,18 +139,9 @@ class ArtworkService
* Uses new authoritative tables only (no legacy joins) and eager-loads
* lightweight relations needed for presentation.
*/
public function browsePublicArtworks(int $perPage = 24): CursorPaginator
public function browsePublicArtworks(int $perPage = 24, string $sort = 'latest'): CursorPaginator
{
$query = Artwork::public()
->published()
->with([
'user:id,name',
'categories' => function ($q) {
$q->select('categories.id', 'categories.content_type_id', 'categories.parent_id', 'categories.name', 'categories.slug', 'categories.sort_order')
->with(['parent:id,parent_id,content_type_id,name,slug', 'contentType:id,slug,name']);
},
])
->orderByDesc('published_at');
$query = $this->browseQuery($sort);
// Use cursor pagination for high-load browse feeds (SEO handled via canonical URLs).
return $query->cursorPaginate($perPage);
@@ -136,7 +151,7 @@ class ArtworkService
* Browse artworks scoped to a content type slug using keyset pagination.
* Applies public + approved + published filters.
*/
public function getArtworksByContentType(string $slug, int $perPage): CursorPaginator
public function getArtworksByContentType(string $slug, int $perPage, string $sort = 'latest'): CursorPaginator
{
$contentType = ContentType::where('slug', strtolower($slug))->first();
@@ -146,19 +161,10 @@ class ArtworkService
throw $e;
}
$query = Artwork::public()
->published()
$query = $this->browseQuery($sort)
->whereHas('categories', function ($q) use ($contentType) {
$q->where('categories.content_type_id', $contentType->id);
})
->with([
'user:id,name',
'categories' => function ($q) {
$q->select('categories.id', 'categories.content_type_id', 'categories.parent_id', 'categories.name', 'categories.slug', 'categories.sort_order')
->with(['parent:id,parent_id,content_type_id,name,slug', 'contentType:id,slug,name']);
},
])
->orderByDesc('published_at');
});
return $query->cursorPaginate($perPage);
}
@@ -169,7 +175,7 @@ class ArtworkService
*
* @param array<int, string> $slugs
*/
public function getArtworksByCategoryPath(array $slugs, int $perPage): CursorPaginator
public function getArtworksByCategoryPath(array $slugs, int $perPage, string $sort = 'latest'): CursorPaginator
{
if (empty($slugs)) {
$e = new ModelNotFoundException();
@@ -214,19 +220,10 @@ class ArtworkService
}
}
$query = Artwork::public()
->published()
$query = $this->browseQuery($sort)
->whereHas('categories', function ($q) use ($current) {
$q->where('categories.id', $current->id);
})
->with([
'user:id,name',
'categories' => function ($q) {
$q->select('categories.id', 'categories.content_type_id', 'categories.parent_id', 'categories.name', 'categories.slug', 'categories.sort_order')
->with(['parent:id,parent_id,content_type_id,name,slug', 'contentType:id,slug,name']);
},
])
->orderByDesc('published_at');
});
return $query->cursorPaginate($perPage);
}