cap scrobble status at max values

This commit is contained in:
jeffvli
2026-05-25 13:07:44 -07:00
parent 95ae474cc6
commit 61c6036d41
@@ -22,6 +22,12 @@ const scrobbleProgressProps = {
const clampPct = (n: number) => Math.min(100, Math.max(0, n)); const clampPct = (n: number) => Math.min(100, Math.max(0, n));
const capForDisplay = (value: number, limit: number) =>
limit > 0 ? Math.min(value, limit) : value;
const progressTowardLimit = (current: number, limit: number) =>
limit > 0 ? clampPct((current / limit) * 100) : 0;
const ScrobbleConditionProgress = ({ value }: { value: number }) => ( const ScrobbleConditionProgress = ({ value }: { value: number }) => (
<Progress {...scrobbleProgressProps} value={value} w="100%" /> <Progress {...scrobbleProgressProps} value={value} w="100%" />
); );
@@ -34,18 +40,25 @@ export const ScrobbleStatus = ({ formattedTime }: { formattedTime: string }) =>
const hookInactive = !scrobbleEnabled || privateMode; const hookInactive = !scrobbleEnabled || privateMode;
const listenedSec = (snapshot.listenedMs / 1000).toFixed(1); const listenedSecRaw = snapshot.listenedMs / 1000;
const listenPercentOfTrack = const listenedSecDisplay = snapshot.submitted
snapshot.trackDurationMs > 0 ? (snapshot.listenedMs / snapshot.trackDurationMs) * 100 : 0; ? snapshot.targetDurationSec
: capForDisplay(listenedSecRaw, snapshot.targetDurationSec);
const durationConditionPct = const listenPercentOfTrackRaw =
snapshot.targetDurationSec > 0 snapshot.trackDurationMs > 0 ? (snapshot.listenedMs / snapshot.trackDurationMs) * 100 : 0;
? clampPct((snapshot.listenedMs / 1000 / snapshot.targetDurationSec) * 100) const listenPercentDisplay = snapshot.submitted
: 0; ? snapshot.targetPercentage
const percentConditionPct = : capForDisplay(listenPercentOfTrackRaw, snapshot.targetPercentage);
snapshot.targetPercentage > 0 && snapshot.trackDurationMs > 0
? clampPct((listenPercentOfTrack / snapshot.targetPercentage) * 100) const durationConditionPct = progressTowardLimit(
: 0; listenedSecDisplay,
snapshot.targetDurationSec,
);
const percentConditionPct = progressTowardLimit(
listenPercentDisplay,
snapshot.targetPercentage,
);
return ( return (
<HoverCard position="top" width={280}> <HoverCard position="top" width={280}>
@@ -87,13 +100,13 @@ export const ScrobbleStatus = ({ formattedTime }: { formattedTime: string }) =>
<> <>
<Stack gap="xs"> <Stack gap="xs">
<Text size="xs"> <Text size="xs">
{`${listenedSec}s / ${snapshot.targetDurationSec}s`} {`${listenedSecDisplay.toFixed(1)}s / ${snapshot.targetDurationSec}s`}
</Text> </Text>
<ScrobbleConditionProgress value={durationConditionPct} /> <ScrobbleConditionProgress value={durationConditionPct} />
</Stack> </Stack>
<Stack gap="xs"> <Stack gap="xs">
<Text size="xs"> <Text size="xs">
{`${listenPercentOfTrack.toFixed(1)}% / ${snapshot.targetPercentage}%`} {`${listenPercentDisplay.toFixed(1)}% / ${snapshot.targetPercentage}%`}
</Text> </Text>
<ScrobbleConditionProgress value={percentConditionPct} /> <ScrobbleConditionProgress value={percentConditionPct} />
</Stack> </Stack>