I need to make loader while click on date. Then loader should work on timeslot before loading the slot
Below shows short code
Dateslot class
Class Dateslot extends component
{
Public function selectedDateSlot()
{
$this->dispatch(‘loading’);
usleep(15000);
$this->dispatch(‘change-dateslot’, [
‘selectedDate’ => $this->selectedDate;
]);
}
public function render()
{
return view('livewire.components dateslot', [
'days' => $this-›days,
'selectedDate' →> $this-›selectedDate,
]);
}
dateslot.blade.php
Shows below the view component for dateslot
div class="py-2">
div class="flex w-full overflow-x-auto no-scrollbar space-x-3 px-2 scrolling-touch"
@foreach ($days as $index => $day)
div class="shrink-0"
input type="radio"
wire:model="selectedDate"
wire: click="selectedDateSlot"
value="{{ $day[ 'datetime' ] }}"
class="peer hidden no-caret" tabindex="-1" readonly required
style="caret-color: transparent; outline: none; box-shadow: none;"/>
‹label style="caret-color: transparent; outline: none; box-shac class="flex flex-col items-center justify-center w-24 px-4 py-2 text-sm md: text-bas text-gray-600 bg-white border border-gray-300 rounded-lg cursor-pointer hover: bg-gray-50 hover: text-black peer-checked:bg-primary-color peer-checked:text-white transition-all duration-
‹span class="text-center dfd">{{ $day['day'] }}</span>
</ label>
</div>
@endforeach
</div›
</div>
Other class is timslot below
Timeslot.php
class Timeslot extends component
{
#[On('selected-dateslot')]
public function getDateTimeslot ($selectedDate = mull)
$this-›selectedDate = $selectedDate;
}
#[On( 'change-dateslot' )]
public function getChangeDateTimeslot ($value)
{
$this-›isLoading = true;
//Start loader
// clear old slots immediately
$this-›slots = []:
$this-›selectedDate = $value['selectedDate'];
$this-›slots = is_array($this-›doctorslot[$this-›selectedDate] ?? null) ? $this-›doctorslot[$this->selectedDate] :[];
$this-›isLoading = false;
//Stop loader after update
//Tell Alpine to hide the Loader
$this-›dispatch('stoploading');
}
public function render()
{
return view(' livewire. components timeslot', [
'doctorslots' => $this-›slots,
'selectedDate' → $this-›selectedDate,
]);
}
For that class view is below. Only short code Timeslot.blade.php
<div x-data="( isLoading: true }"
x-on: loading="isLoading = true"
x-on:stoploading="isLoading = false"
>
‹ template x-if="isLoading"›
‹div class="text-center py-2 text-gray-500"›Loading... </div>
‹/ template>
‹I-- Slots (when not loading) -->
‹div x-show="lisLoading" class="mt-2" >
@if (count ($doctorslots))
‹div class="grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 1g:grid-cols-8
@foreach ($doctorslots as $slotKey →> $slot)
‹ div wire:key="slot-{f $slotKey }]"›
<input type="radio"
wire:model-"selectedSlot" wire:click="selectedTime"
id="timeslot-ft $slotkey J"
name="selectedSlot" class="hidden peer" value="{{ $slot }}">
These are the child class. I only required the loader while click on date and show before appear or change of timeslot.
I cannot get any loader only gets each timeslot
{is missing