Files
readest/apps/readest-app/src/app/reader/hooks/useCurrentTime.ts
T
scinac 38552a0c2e feat(reader): adding current Time and Battery to Footer (#3306) (#3402)
* added current time to desktop bar

* added time prototype to footer, needs code cleanup and settings toggle

* fixed settings toggle, added translations and code cleanup

* added battery support and moved Statusbar to own Component

* #3306 added 24 hour clock support

* refactored code styling and getting rid of any type in battery hook

* Add battery info for Tauri Apps

---------

Co-authored-by: Huang Xin <chrox.huang@gmail.com>
2026-03-03 17:10:13 +01:00

26 lines
650 B
TypeScript

import { useEffect, useState, useMemo } from 'react';
export function useCurrentTime(enabled: boolean, use24Hour = true, intervalMs = 10000) {
const [currentTime, setCurrentTime] = useState(() => new Date());
useEffect(() => {
if (!enabled) return;
const timer = setInterval(() => {
setCurrentTime(new Date());
}, intervalMs);
return () => clearInterval(timer);
}, [enabled, intervalMs]);
return useMemo(() => {
if (!enabled) return '';
return currentTime.toLocaleTimeString([], {
hour: '2-digit',
minute: '2-digit',
hour12: !use24Hour,
});
}, [currentTime, enabled, use24Hour]);
}