From 099344e26cb462675f38ca72ef6bc56fd3b63ce5 Mon Sep 17 00:00:00 2001 From: devoalda Date: Thu, 10 Aug 2023 22:36:26 +0800 Subject: [PATCH] fix(Cache): Cached pomo time in session --- app/Http/Livewire/Pomo/Timer.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Http/Livewire/Pomo/Timer.php b/app/Http/Livewire/Pomo/Timer.php index a967683..90fc639 100644 --- a/app/Http/Livewire/Pomo/Timer.php +++ b/app/Http/Livewire/Pomo/Timer.php @@ -2,6 +2,7 @@ namespace App\Http\Livewire\Pomo; +use Illuminate\View\View; use Livewire\Component; class Timer extends Component @@ -42,7 +43,7 @@ class Timer extends Component public function tick(): void { - if($this->time > 0) { + if ($this->time > 0) { $this->time--; } else { $this->countdown = false; @@ -52,12 +53,18 @@ class Timer extends Component public function mount($time = null): void { - $this->time = $time ?? $this->time; + $this->time = session('time') ?? $time ?? $this->time; + $this->countdown = false; } - public function render(): \Illuminate\View\View + public function render(): View { + // Cache time in session + session(['time' => $this->time]); + $this->time = session('time') ?? $this->time; + + return view('livewire.pomo.timer', [ 'time' => $this->time, 'countdown' => $this->countdown,