Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/Livewire/ProgramEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ public function formattedDuration(): string

public function totalDuration(): int
{
return array_reduce(
if (empty($this->phases)) {
return 0;
}

$total = array_reduce(
$this->phases,
static function (int $carry, array $p): int {
$repTime = $p['duration'] * $p['repetitions'];
Expand All @@ -226,6 +230,9 @@ static function (int $carry, array $p): int {
},
0,
);

// The last phase's cooldown is never executed (timer goes straight to COMPLETED).
return $total - (int) ($this->phases[array_key_last($this->phases)]['cooldown'] ?? 0);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions app/Livewire/TimerScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public function start(): void
$runner = app(TimerRunner::class);
$program = Program::with('phases')->findOrFail($this->programId);

if ($program->phases->isEmpty()) {
return;
}

$this->programTotalDuration = $program->totalDuration();
$runner->load($program);
$runner->start();
Expand Down
21 changes: 14 additions & 7 deletions resources/views/livewire/timer-screen.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,20 @@ class="text-gray-800 text-xs mt-2 select-none"

{{-- Primary action --}}
@if($state === StateMachine::idle)
<button
wire:click="start"
class="w-full bg-blue-600 hover:bg-blue-500 active:bg-blue-700 text-white font-bold
text-xl py-5 rounded-3xl transition-colors shadow-lg shadow-blue-900/40"
>
Start
</button>
@if(count($phases) === 0)
<div class="w-full text-center text-amber-400 text-sm font-medium py-4 px-4
bg-amber-950/40 border border-amber-800/40 rounded-3xl">
No phases — edit this program to add at least one phase before starting.
</div>
@else
<button
wire:click="start"
class="w-full bg-blue-600 hover:bg-blue-500 active:bg-blue-700 text-white font-bold
text-xl py-5 rounded-3xl transition-colors shadow-lg shadow-blue-900/40"
>
Start
</button>
@endif

@elseif($state === StateMachine::prepare)
{{-- No primary action during prepare — user just waits --}}
Expand Down
Loading