fixed browse and tailwindcss style
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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, [
|
||||
|
||||
Reference in New Issue
Block a user