support collections

This commit is contained in:
2024-04-23 08:12:56 +10:00
parent 71f048fb00
commit 00afc7a1d3
2 changed files with 15 additions and 9 deletions

View File

@@ -49,16 +49,22 @@
function updateFiles(result) { function updateFiles(result) {
Alpine.store('files', []); Alpine.store('files', []);
result = result.filter((item) => item.length > 0); // Check if result is a string or a collection
if (typeof result === 'string') {
result = result.split(',').filter((item) => item.length > 0);
Promise.all(result.map(fileName => new Promise(resolve => { Promise.all(result.map(fileName => new Promise(resolve => {
SM.mediaDetails(fileName, (details) => { SM.mediaDetails(fileName, (details) => {
details.extension = fileName.split('.').pop(); resolve(details);
resolve(details); });
}))).then(detailsArray => {
Alpine.store('files', detailsArray);
}); });
}))).then(detailsArray => {
Alpine.store('files', detailsArray); } else if (Array.isArray(result)) {
}); // If result is a collection, directly place it in the store
Alpine.store('files', result);
}
const elem = document.getElementById('{{ $name }}'); const elem = document.getElementById('{{ $name }}');
if(elem) { if(elem) {

View File

@@ -10,6 +10,6 @@
</div> </div>
<article class="content mb-4">{!! $post->content !!}</article> <article class="content mb-4">{!! $post->content !!}</article>
<x-ui.gallery class="mt-16" value="{{ \App\Helpers::arrayToString($post->files('gallery')->pluck('name')->toArray()) }}" /> <x-ui.gallery class="mt-16" value="{{ \App\Helpers::arrayToString($post->files('gallery')->pluck('name')->toArray()) }}" />
<x-ui.filelist class="mt-16" value="{{ \App\Helpers::arrayToString($post->files()->orderBy('title')->get()->pluck('name')->toArray()) }}" /> <x-ui.filelist class="mt-16" value="{{ \App\Helpers::arrayToString($post->files()->orderBy('name')->get()) }}" />
</x-container> </x-container>
</x-layout> </x-layout>