Enhance FindSliderBySlugTask to filter slides based on current time, ensuring only active slides within the valid time range are retrieved; update SlidesRelationManager to set default and minimum dates for start and end times. Improve Slider component styling for better visibility during loading state.
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Containers\Widget\Tasks;
|
||||
|
||||
use App\Containers\Widget\Models\Slider;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class FindSliderBySlugTask
|
||||
{
|
||||
@@ -12,15 +13,19 @@ class FindSliderBySlugTask
|
||||
$cacheKey = 'slider_' . $slug;
|
||||
|
||||
return Cache::remember($cacheKey, now()->addHour(), function () use ($slug) {
|
||||
$now = Carbon::now(); // Получаем текущее время один раз
|
||||
|
||||
$slider = Slider::query()
|
||||
->where('slug', $slug)
|
||||
->where('is_active', true)
|
||||
->with(['slides' => function($query) {
|
||||
$query->where('is_active', true);
|
||||
->with(['slides' => function($query) use ($now) {
|
||||
$query->where('is_active', true)
|
||||
->where('start_time', '<=', $now)
|
||||
->where('end_time', '>=', $now);
|
||||
}])
|
||||
->firstOrFail();
|
||||
|
||||
return $slider ?: null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,8 +206,7 @@ class SlidesRelationManager extends RelationManager
|
||||
->native(false)
|
||||
->displayFormat('d/m/Y H:i')
|
||||
->seconds(false)
|
||||
->default(Carbon::now())
|
||||
->minDate(fn($record, $context) => $context === 'edit' ? $record?->start_time : Carbon::now()),
|
||||
->default(Carbon::now()),
|
||||
|
||||
DateTimePicker::make('end_time')
|
||||
->label('Дата окончания показа')
|
||||
@@ -216,7 +215,6 @@ class SlidesRelationManager extends RelationManager
|
||||
->displayFormat('d/m/Y H:i')
|
||||
->seconds(false)
|
||||
->default(Carbon::now()->addWeeks(2))
|
||||
->minDate(fn (Forms\Get $get) => $get('start_time') ?: Carbon::now()),
|
||||
]),
|
||||
|
||||
TextInput::make('link')
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<MetaTags :seo="seo" />
|
||||
|
||||
<MainPageNavBar :sections="$page.props.navigation" />
|
||||
<Slider class="bvi-hide" slider-id="quos-velit-quisquam" />
|
||||
<Slider class="bvi-hide bg-gray-300" slider-id="quos-velit-quisquam" />
|
||||
|
||||
<section class="max-w-screen-xl w-full mx-auto px-4 py-3 pb-10">
|
||||
<PostSection :posts="posts" />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div v-if="loading" class="relative z-0 min-h-[calc(100vh)] items-center">
|
||||
<div v-if="loading" class="relative z-0 min-h-[calc(100vh)] items-center bg-gray-500">
|
||||
<div class="group block rounded-xl overflow-hidden animate-pulse min-h-[calc(100vh)] bg-gray-200"></div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user