mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-21 23:05:46 +00:00
fix(fullscreen): respect Settings clock format on wall clock (#1025)
* fix(fullscreen): respect Settings clock format on wall clock The fullscreen player corner clock always used the browser locale default (12-hour). Route it through formatClockTime and authStore.clockFormat so 24-hour matches queue ETA and sleep-timer preview. * docs(changelog): fullscreen clock format fix (PR #1025)
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { memo, useEffect, useState } from 'react';
|
||||
|
||||
function formatClock(): string {
|
||||
return new Date().toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' });
|
||||
}
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useAuthStore } from '../../store/authStore';
|
||||
import { formatClockTime } from '../../utils/format/formatClockTime';
|
||||
|
||||
/**
|
||||
* Standalone wall-clock for the fullscreen player. Owns its own state so the
|
||||
@@ -10,11 +9,19 @@ function formatClock(): string {
|
||||
* the minute rollover) and pauses while the window/tab is hidden.
|
||||
*/
|
||||
export const FsClock = memo(function FsClock() {
|
||||
const [time, setTime] = useState(formatClock);
|
||||
const clockFormat = useAuthStore(s => s.clockFormat);
|
||||
const { i18n } = useTranslation();
|
||||
|
||||
const formatNow = () => formatClockTime(Date.now(), clockFormat, i18n.language);
|
||||
const [time, setTime] = useState(formatNow);
|
||||
|
||||
useEffect(() => {
|
||||
setTime(formatNow());
|
||||
}, [clockFormat, i18n.language]);
|
||||
|
||||
useEffect(() => {
|
||||
let id: number | undefined;
|
||||
const tick = () => setTime(formatClock());
|
||||
const tick = () => setTime(formatClockTime(Date.now(), clockFormat, i18n.language));
|
||||
const sync = () => {
|
||||
if (document.hidden) {
|
||||
if (id !== undefined) { clearInterval(id); id = undefined; }
|
||||
@@ -29,7 +36,7 @@ export const FsClock = memo(function FsClock() {
|
||||
if (id !== undefined) clearInterval(id);
|
||||
document.removeEventListener('visibilitychange', sync);
|
||||
};
|
||||
}, []);
|
||||
}, [clockFormat, i18n.language]);
|
||||
|
||||
return <span className="fsp-clock">{time}</span>;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user