Improve creator studio browsing and versioning
This commit is contained in:
@@ -53,6 +53,7 @@ final class CreatorStudioContentService
|
||||
$bucket = $fixedBucket ?: $this->normalizeBucket((string) ($filters['bucket'] ?? 'all'));
|
||||
$search = trim((string) ($filters['q'] ?? ''));
|
||||
$sort = $this->normalizeSort((string) ($filters['sort'] ?? 'updated_desc'));
|
||||
$contentType = (string) ($filters['content_type'] ?? 'all');
|
||||
$category = (string) ($filters['category'] ?? 'all');
|
||||
$tag = trim((string) ($filters['tag'] ?? ''));
|
||||
$visibility = (string) ($filters['visibility'] ?? 'all');
|
||||
@@ -63,7 +64,7 @@ final class CreatorStudioContentService
|
||||
|
||||
$items = $module === 'all'
|
||||
? SupportCollection::make($this->providers())->flatMap(fn (CreatorStudioProvider $provider) => $provider->items($user, $this->providerBucket($bucket), 200))
|
||||
: $this->provider($module)?->items($user, $this->providerBucket($bucket), 240) ?? SupportCollection::make();
|
||||
: $this->provider($module)?->items($user, $this->providerBucket($bucket), 0) ?? SupportCollection::make();
|
||||
|
||||
if ($bucket === 'featured') {
|
||||
$items = $items->filter(fn (array $item): bool => (bool) ($item['featured'] ?? false));
|
||||
@@ -91,6 +92,19 @@ final class CreatorStudioContentService
|
||||
});
|
||||
}
|
||||
|
||||
$artworkFilterItems = null;
|
||||
|
||||
if ($module === 'artworks') {
|
||||
$artworkFilterItems = $items->values();
|
||||
}
|
||||
|
||||
if ($module === 'artworks' && $contentType !== 'all') {
|
||||
$items = $items->filter(function (array $item) use ($contentType): bool {
|
||||
return SupportCollection::make($item['taxonomies']['content_types'] ?? [])
|
||||
->contains(fn (array $entry): bool => (string) ($entry['slug'] ?? '') === $contentType);
|
||||
});
|
||||
}
|
||||
|
||||
if ($module === 'artworks' && $category !== 'all') {
|
||||
$items = $items->filter(function (array $item) use ($category): bool {
|
||||
return SupportCollection::make($item['taxonomies']['categories'] ?? [])
|
||||
@@ -141,6 +155,7 @@ final class CreatorStudioContentService
|
||||
'bucket' => $bucket,
|
||||
'q' => $search,
|
||||
'sort' => $sort,
|
||||
'content_type' => $contentType,
|
||||
'category' => $category,
|
||||
'tag' => $tag,
|
||||
'visibility' => $visibility,
|
||||
@@ -174,12 +189,13 @@ final class CreatorStudioContentService
|
||||
['value' => 'title_asc', 'label' => 'Title A-Z'],
|
||||
],
|
||||
'advanced_filters' => $this->advancedFilters($module, $items, [
|
||||
'content_type' => $contentType,
|
||||
'category' => $category,
|
||||
'tag' => $tag,
|
||||
'visibility' => $visibility,
|
||||
'activity_state' => $activityState,
|
||||
'stale' => $stale,
|
||||
]),
|
||||
], $artworkFilterItems),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -323,34 +339,65 @@ final class CreatorStudioContentService
|
||||
/**
|
||||
* @param array<string, string> $currentFilters
|
||||
*/
|
||||
private function advancedFilters(string $module, SupportCollection $items, array $currentFilters): array
|
||||
private function advancedFilters(string $module, SupportCollection $items, array $currentFilters, ?SupportCollection $optionItems = null): array
|
||||
{
|
||||
return match ($module) {
|
||||
'artworks' => [
|
||||
[
|
||||
'key' => 'category',
|
||||
'label' => 'Category',
|
||||
'type' => 'select',
|
||||
'value' => $currentFilters['category'] ?? 'all',
|
||||
'options' => array_merge([
|
||||
['value' => 'all', 'label' => 'All categories'],
|
||||
], $items
|
||||
->flatMap(fn (array $item) => $item['taxonomies']['categories'] ?? [])
|
||||
->unique('slug')
|
||||
->sortBy('name')
|
||||
->map(fn (array $entry): array => [
|
||||
'value' => (string) ($entry['slug'] ?? ''),
|
||||
'label' => (string) ($entry['name'] ?? 'Category'),
|
||||
])->values()->all()),
|
||||
],
|
||||
[
|
||||
'key' => 'tag',
|
||||
'label' => 'Tag',
|
||||
'type' => 'search',
|
||||
'value' => $currentFilters['tag'] ?? '',
|
||||
'placeholder' => 'Filter by tag',
|
||||
],
|
||||
],
|
||||
'artworks' => (function () use ($items, $currentFilters, $optionItems): array {
|
||||
$optionItems = $optionItems ?? $items;
|
||||
$selectedContentType = $currentFilters['content_type'] ?? 'all';
|
||||
|
||||
$contentTypeOptions = array_merge([
|
||||
['value' => 'all', 'label' => 'All content types'],
|
||||
], $optionItems
|
||||
->flatMap(fn (array $item) => $item['taxonomies']['content_types'] ?? [])
|
||||
->unique('slug')
|
||||
->sortBy('name')
|
||||
->map(fn (array $entry): array => [
|
||||
'value' => (string) ($entry['slug'] ?? ''),
|
||||
'label' => (string) ($entry['name'] ?? 'Content type'),
|
||||
])->values()->all());
|
||||
|
||||
$categoryItems = $selectedContentType === 'all'
|
||||
? $optionItems
|
||||
: $optionItems->filter(function (array $item) use ($selectedContentType): bool {
|
||||
return SupportCollection::make($item['taxonomies']['content_types'] ?? [])
|
||||
->contains(fn (array $entry): bool => (string) ($entry['slug'] ?? '') === $selectedContentType);
|
||||
});
|
||||
|
||||
return [
|
||||
[
|
||||
'key' => 'content_type',
|
||||
'label' => 'Content Type',
|
||||
'type' => 'select',
|
||||
'value' => $currentFilters['content_type'] ?? 'all',
|
||||
'options' => $contentTypeOptions,
|
||||
],
|
||||
[
|
||||
'key' => 'category',
|
||||
'label' => 'Category',
|
||||
'type' => 'select',
|
||||
'value' => $currentFilters['category'] ?? 'all',
|
||||
'options' => array_merge([
|
||||
['value' => 'all', 'label' => 'All categories', 'content_type_slug' => 'all'],
|
||||
], $categoryItems
|
||||
->flatMap(fn (array $item) => $item['taxonomies']['categories'] ?? [])
|
||||
->unique('slug')
|
||||
->sortBy('name')
|
||||
->map(fn (array $entry): array => [
|
||||
'value' => (string) ($entry['slug'] ?? ''),
|
||||
'label' => (string) ($entry['name'] ?? 'Category'),
|
||||
'content_type_slug' => (string) ($entry['content_type_slug'] ?? 'all'),
|
||||
])->values()->all()),
|
||||
],
|
||||
[
|
||||
'key' => 'tag',
|
||||
'label' => 'Tag',
|
||||
'type' => 'search',
|
||||
'value' => $currentFilters['tag'] ?? '',
|
||||
'placeholder' => 'Filter by tag',
|
||||
],
|
||||
];
|
||||
})(),
|
||||
'collections' => [[
|
||||
'key' => 'visibility',
|
||||
'label' => 'Visibility',
|
||||
|
||||
Reference in New Issue
Block a user