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:
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { canSkipPrev, canSkipNext, repeatLabel, volumeIcon, inputNumber } from '#lib/player/controls.js';
|
||||
import {
|
||||
ArrowLeft, SkipBack, SkipForward, Play, Pause, Loader2,
|
||||
Shuffle, Repeat, Repeat1,
|
||||
Volume2, Volume1, VolumeX,
|
||||
ListMusic
|
||||
} from 'lucide-svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
@@ -27,20 +27,10 @@
|
||||
// smoothly between server ticks. Shares the helper with PlayerBar.
|
||||
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 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
|
||||
);
|
||||
const skipPrevDisabled = $derived(!canSkipPrev(player));
|
||||
const skipNextDisabled = $derived(!canSkipNext(player));
|
||||
const repeatText = $derived(repeatLabel(player.repeat));
|
||||
const VolumeIcon = $derived(volumeIcon(player.volume));
|
||||
|
||||
// The backdrop takes the cover's dominant colour, as Android's Now
|
||||
// Playing does. The colour is held until the next cover's
|
||||
@@ -58,14 +48,8 @@
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -249,7 +233,7 @@
|
||||
<button
|
||||
type="button"
|
||||
onclick={cycleRepeat}
|
||||
aria-label={repeatLabel}
|
||||
aria-label={repeatText}
|
||||
aria-pressed={player.repeat !== 'off'}
|
||||
class="flex items-center justify-center min-h-[44px] min-w-[44px] rounded
|
||||
{player.repeat !== 'off' ? 'text-accent-fg' : 'text-text-secondary hover:text-text-primary'}
|
||||
|
||||
Reference in New Issue
Block a user