Web: zywy zegar paska statusu i odliczany czas przerwy w macecie telefonu
This commit is contained in:
@@ -1,6 +1,29 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { CalendarClock, Wifi } from 'lucide-react';
|
||||
import { StreakDots } from './StreakDots';
|
||||
|
||||
const timeFmt = new Intl.DateTimeFormat(undefined, { hour: '2-digit', minute: '2-digit' });
|
||||
|
||||
// zegar paska statusu = prawdziwa godzina „tu i teraz”
|
||||
function useClock() {
|
||||
const [now, setNow] = useState(() => new Date());
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => setNow(new Date()), 5000);
|
||||
return () => clearInterval(id);
|
||||
}, []);
|
||||
return timeFmt.format(now);
|
||||
}
|
||||
|
||||
// odliczany w pętli czas przerwy między seriami
|
||||
function useBreakCountdown(from = 45) {
|
||||
const [secs, setSecs] = useState(from);
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => setSecs((s) => (s > 0 ? s - 1 : from)), 1000);
|
||||
return () => clearInterval(id);
|
||||
}, [from]);
|
||||
return `0:${String(secs).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
function SignalIcon() {
|
||||
return (
|
||||
<span aria-hidden="true" className="flex items-end gap-[1.5px]">
|
||||
@@ -41,6 +64,8 @@ function SideButtons() {
|
||||
|
||||
/** Mock iPhone’a 16 Pro (tytan, Dynamic Island) z odpaloną apką „Trwa trening”. */
|
||||
export function PhoneMock() {
|
||||
const clock = useClock();
|
||||
const przerwa = useBreakCountdown();
|
||||
return (
|
||||
<div
|
||||
className="relative mx-auto w-[300px]"
|
||||
@@ -59,7 +84,9 @@ export function PhoneMock() {
|
||||
|
||||
{/* pasek statusu iOS */}
|
||||
<div className="flex items-center justify-between px-[26px] pt-[11px]">
|
||||
<span className="text-[13px] font-semibold tracking-tight text-ink">18:42</span>
|
||||
<span className="text-[13px] font-semibold tracking-tight text-ink tabular-nums">
|
||||
{clock}
|
||||
</span>
|
||||
<span className="flex items-center gap-[5px]">
|
||||
<SignalIcon />
|
||||
<Wifi size={12} aria-hidden="true" className="text-ink" strokeWidth={2.6} />
|
||||
@@ -114,7 +141,9 @@ export function PhoneMock() {
|
||||
|
||||
<div className="mt-2.5 flex items-center justify-between rounded-md border border-line bg-input px-2.5 py-2">
|
||||
<span className="text-[11px] text-dim">Przerwa</span>
|
||||
<span className="font-mono text-sm font-semibold text-accent">0:45</span>
|
||||
<span className="font-mono text-sm font-semibold text-accent tabular-nums">
|
||||
{przerwa}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="mt-2.5 h-8 rounded-md bg-(image:--btn-grad) text-center font-sans text-[12.5px] font-bold leading-8 text-accent-ink shadow-(--btn-shadow)">
|
||||
|
||||
Reference in New Issue
Block a user