What seems to be the problem:
I may not have understood how the events work yet very well, perhaps because of the parent and child components, Idk.
In my navigation bar I have 4 menu options in which in each one of them there is a component that returns the number of orders in progress (new, to be prepared, to be delivered…)
each event has a ‘refreshNumber’ listener => ‘refresh’, so far everything has worked perfectly, whenever there is a change in the order status it calls the event and update the numbers.
It happens that when trying to implement a notification sound at the arrival of a new order, the event is not called. I tried everything, since javascript, alpine js, through the components, nothing worked.
Livewire v2.3.16
`class ShowOrderNumberComponent extends Component
{
public $number;
protected $listeners =
[
'refreshNumber' => '$refresh',
];
public function mount()
{
if(Auth::user()->is_admin != 1)
{
abort(403, 'Sem permissão!');
}
}
public function render()
{
$this->number = Order::whereIn('status', ['W','P'])->count();
if($this->number == 0)
{
$this->number = null;
}
return <<<'blade'
<div>
<small class="inline-block align-top text-xs px-1 ml-1 bg-green-700 rounded-full text-white">
{{$this->number}}
</small>
</div>
blade;
}
}`
tried this inside:
protected $listeners =
[
'refreshNumber' => '$refresh',
'newOrder' => 'newOrder',
];
public function newOrder()
{
dd(new);
}
with no success!
I was thinking to play the sound like this:
new Audio("{{url('audio_path.mp3')}}").play();
in the script tag of admin dashboard
Anyone please can help me to understand how can I implement this, and if exist any other way to optimize my code?
Thanks a lot!