mirror of
https://github.com/p-stream/p-stream.git
synced 2026-04-04 17:49:44 +00:00
Use 12 hour clock + add box around time (#58)
* Use 12 hour clock + box around time * Fix ref
This commit is contained in:
parent
6f3437277d
commit
ac5d4443b1
3 changed files with 24 additions and 11 deletions
|
|
@ -37,6 +37,14 @@ function ThumbnailDisplay(props: { at: number; show: boolean }) {
|
|||
});
|
||||
}, [props.at]);
|
||||
|
||||
// Keep time label width consistent and avoid recomputing
|
||||
const formattedTime = useMemo(
|
||||
() => formatSeconds(Math.max(props.at, 0), durationExceedsHour(props.at)),
|
||||
[props.at],
|
||||
);
|
||||
const transformX =
|
||||
offsets.offscreenLeft > 0 ? offsets.offscreenLeft : -offsets.offscreenRight;
|
||||
|
||||
if (!props.show) return null;
|
||||
|
||||
return (
|
||||
|
|
@ -45,11 +53,7 @@ function ThumbnailDisplay(props: { at: number; show: boolean }) {
|
|||
<div ref={ref}>
|
||||
<div
|
||||
style={{
|
||||
transform: `translateX(${
|
||||
offsets.offscreenLeft > 0
|
||||
? offsets.offscreenLeft
|
||||
: -offsets.offscreenRight
|
||||
}px)`,
|
||||
transform: `translateX(${transformX}px)`,
|
||||
}}
|
||||
>
|
||||
{currentThumbnail && (
|
||||
|
|
@ -58,11 +62,8 @@ function ThumbnailDisplay(props: { at: number; show: boolean }) {
|
|||
className="h-24 border rounded-xl border-gray-800"
|
||||
/>
|
||||
)}
|
||||
<p className="text-center mt-1">
|
||||
{formatSeconds(
|
||||
Math.max(props.at, 0),
|
||||
durationExceedsHour(props.at),
|
||||
)}
|
||||
<p className="mt-1 mx-auto text-center border rounded-xl border-gray-800 px-3 py-1 backdrop-blur-lg bg-black bg-opacity-20 w-max">
|
||||
{formattedTime}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { VideoPlayerButton } from "@/components/player/internals/Button";
|
|||
import { VideoPlayerTimeFormat } from "@/stores/player/slices/interface";
|
||||
import { usePlayerStore } from "@/stores/player/store";
|
||||
import { durationExceedsHour, formatSeconds } from "@/utils/formatSeconds";
|
||||
import { uses12HourClock } from "@/utils/uses12HourClock";
|
||||
|
||||
export function Time(props: { short?: boolean }) {
|
||||
const timeFormat = usePlayerStore((s) => s.interface.timeFormat);
|
||||
|
|
@ -63,7 +64,11 @@ export function Time(props: { short?: boolean }) {
|
|||
timeLeft,
|
||||
duration,
|
||||
formatParams: {
|
||||
timeFinished: { hour: "numeric", minute: "numeric" },
|
||||
timeFinished: {
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
hour12: uses12HourClock(),
|
||||
},
|
||||
},
|
||||
})}
|
||||
</span>
|
||||
|
|
|
|||
7
src/utils/uses12HourClock.ts
Normal file
7
src/utils/uses12HourClock.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
export function uses12HourClock() {
|
||||
const parts = new Intl.DateTimeFormat(undefined, {
|
||||
hour: "numeric",
|
||||
}).formatToParts(new Date());
|
||||
// If a dayPeriod ("AM"/"PM" or localized equivalent) appears, it's 12-hour
|
||||
return parts.some((p) => p.type === "dayPeriod");
|
||||
}
|
||||
Loading…
Reference in a new issue