diff --git a/app/Livewire/OnlineCalendar.php b/app/Livewire/OnlineCalendar.php index 920cb1786..9a122927b 100644 --- a/app/Livewire/OnlineCalendar.php +++ b/app/Livewire/OnlineCalendar.php @@ -18,7 +18,7 @@ class OnlineCalendar extends Component public $selectedMonth; - public $selectedDate; + public $selectedDate = 'all'; public $months = []; @@ -26,8 +26,7 @@ public function mount() { $this->selectedYear = Carbon::now()->year; $this->selectedMonth = Carbon::now()->month; - $this->selectedDate = $this->selectedMonth.'/'.$this->selectedYear; - // Default to all languages so the list is not silently reduced/restored by locale. + $this->selectedDate = 'all'; $this->selectedLanguage = ''; $this->months = $this->baseQuery() @@ -48,13 +47,6 @@ public function mount() }) ->values() ->toArray(); - - if (! empty($this->months)) { - $parts = explode('/', $this->months[0]['id']); - $this->selectedMonth = (int) $parts[0]; - $this->selectedYear = (int) ($parts[1] ?? $this->selectedYear); - $this->selectedDate = $this->selectedMonth.'/'.$this->selectedYear; - } } public function updatedSelectedDate(): void @@ -69,15 +61,18 @@ public function updatedSelectedLanguage(): void public function render() { - $parts = explode('/', (string) $this->selectedDate); - $this->selectedMonth = (int) ($parts[0] ?: $this->selectedMonth); - $this->selectedYear = (int) ($parts[1] ?? $this->selectedYear); + $query = $this->baseQuery()->orderBy('start_date'); - $events = $this->baseQuery() - ->whereMonth('start_date', $this->selectedMonth) - ->whereYear('start_date', $this->selectedYear) - ->orderBy('start_date') - ->get(); + if ($this->selectedDate && $this->selectedDate !== 'all') { + $parts = explode('/', (string) $this->selectedDate); + $this->selectedMonth = (int) ($parts[0] ?: $this->selectedMonth); + $this->selectedYear = (int) ($parts[1] ?? $this->selectedYear); + + $query->whereMonth('start_date', $this->selectedMonth) + ->whereYear('start_date', $this->selectedYear); + } + + $events = $query->get(); $events->each(function ($event) { $event->title = str_limit($event->title, 50); @@ -113,13 +108,17 @@ public function render() ->toArray(); $totalUpcoming = $this->baseQuery()->count(); + $monthLabel = $this->selectedDate === 'all' || ! $this->selectedDate + ? 'all upcoming months' + : Carbon::createFromDate($this->selectedYear, $this->selectedMonth, 1)->format('F Y'); return view('livewire.online-calendar', [ 'countryNames' => $this->getCountryNamesFromEvents($events), 'languages' => $languages, - 'filteredEvents' => $filteredEvents->paginate(50), + 'filteredEvents' => $filteredEvents->paginate(24), 'totalUpcoming' => $totalUpcoming, 'visibleCount' => $filteredEvents->count(), + 'monthLabel' => $monthLabel, ]); } diff --git a/resources/views/livewire/online-calendar.blade.php b/resources/views/livewire/online-calendar.blade.php index 50b6c19c3..777c88905 100644 --- a/resources/views/livewire/online-calendar.blade.php +++ b/resources/views/livewire/online-calendar.blade.php @@ -13,11 +13,10 @@ wire:model.live="selectedDate" class="w-full appearance-none rounded-full border border-slate-200 bg-white py-3 pl-12 pr-10 text-slate-500 font-semibold focus:outline-none focus:ring-2 focus:ring-[#1C4DA1]" > - @forelse($months as $month) + + @foreach($months as $month) - @empty - - @endforelse + @endforeach @@ -44,20 +43,20 @@ class="w-full appearance-none rounded-full border border-slate-200 bg-white py-3
-
+

Showing {{ $visibleCount }} of {{ $totalUpcoming }} upcoming open online activities - @if($selectedDate) - for {{ \Carbon\Carbon::createFromDate($selectedYear, $selectedMonth, 1)->format('F Y') }} - @endif + for {{ $monthLabel }}

@if(count($filteredEvents) > 0)
@foreach($filteredEvents as $event) - @include('online-calendar._oc-event-simple') +
+ @include('online-calendar._oc-event-simple') +
@endforeach
-
+
{{ $filteredEvents->links('vendor.pagination') }}
@else diff --git a/resources/views/online-calendar/oc-index.blade.php b/resources/views/online-calendar/oc-index.blade.php index 779e038d4..308c5ab72 100644 --- a/resources/views/online-calendar/oc-index.blade.php +++ b/resources/views/online-calendar/oc-index.blade.php @@ -16,7 +16,8 @@ @include('components.tailwind') @include('components.livewire') -@include('components.alpine') +{{-- Do not include Alpine v2 here. Livewire 3 already ships Alpine v3; + loading Alpine v2 breaks Livewire DOM updates (filters appear to do nothing). --}} @section('content')