refactor(web): the play bar and Now Playing share one set of transport rules (DRY W1)

PlayerBar and the Now Playing page each carried their own copy of when
Previous and Next are enabled, the repeat label, the volume icon and the
range-input handlers, and the 3-second "restart rather than go back"
threshold was written in both and again in store.skipPrev.
lib/player/controls.ts now holds them once (canSkipPrev, canSkipNext,
repeatLabel, volumeIcon, inputNumber, RESTART_THRESHOLD_SEC), and the store
reads its threshold from there. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 03:06:36 -05:00
co-authored by Claude Opus 5.5
parent 02cecc4eb7
commit 14afd86b8e
5 changed files with 78 additions and 50 deletions
+9 -25
View File
@@ -1,8 +1,8 @@
<script lang="ts">
import { canSkipPrev, canSkipNext, repeatLabel, volumeIcon, inputNumber } from '#lib/player/controls.js';
import {
SkipBack, SkipForward, Play, Pause, Loader2,
Shuffle, Repeat, Repeat1,
Volume2, Volume1, VolumeX,
ListMusic
} from 'lucide-svelte';
import {
@@ -25,29 +25,13 @@
// Reset on track/play-state change via the helper's $effect.
const smoothed = useSmoothPosition();
const skipPrevDisabled = $derived(player.index === 0 && player.position < 3);
const skipNextDisabled = $derived(
player.index === player.queue.length - 1 && player.repeat === 'off'
);
const skipPrevDisabled = $derived(!canSkipPrev(player));
const skipNextDisabled = $derived(!canSkipNext(player));
const repeatText = $derived(repeatLabel(player.repeat));
const VolumeIcon = $derived(volumeIcon(player.volume));
const repeatLabel = $derived(
player.repeat === 'off' ? 'Repeat off' :
player.repeat === 'all' ? 'Repeat all' : 'Repeat one'
);
const VolumeIcon = $derived(
player.volume === 0 ? VolumeX :
player.volume < 0.5 ? Volume1 : Volume2
);
function onSeekInput(e: Event) {
const v = Number((e.currentTarget as HTMLInputElement).value);
seekTo(v);
}
function onVolumeInput(e: Event) {
const v = Number((e.currentTarget as HTMLInputElement).value);
setVolume(v);
}
const onSeekInput = (e: Event) => seekTo(inputNumber(e));
const onVolumeInput = (e: Event) => setVolume(inputNumber(e));
function onCoverError(e: Event) {
(e.currentTarget as HTMLImageElement).src = FALLBACK_COVER;
}
@@ -191,7 +175,7 @@
</button>
<button
type="button"
aria-label={repeatLabel}
aria-label={repeatText}
onclick={cycleRepeat}
class="flex h-8 w-8 items-center justify-center rounded-full transition-colors {player.repeat !== 'off'
? 'bg-accent-tint text-accent-fg'
@@ -403,7 +387,7 @@
</button>
<button
type="button"
aria-label={repeatLabel}
aria-label={repeatText}
onclick={cycleRepeat}
class="flex h-9 w-9 items-center justify-center rounded-full transition-colors {player.repeat !== 'off'
? 'bg-accent-tint text-accent-fg'