[skip ci] Initial commit — CodexBar Mobile Expo app
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Text } from "react-native";
|
||||
import { formatResetCountdown, formatResetCountdownISO } from "@/lib/timeUtils";
|
||||
|
||||
interface ResetCountdownProps {
|
||||
resetAtSeconds?: number;
|
||||
resetAtISO?: string;
|
||||
}
|
||||
|
||||
export function ResetCountdown({ resetAtSeconds, resetAtISO }: ResetCountdownProps) {
|
||||
const getLabel = () => {
|
||||
if (resetAtSeconds !== undefined) return formatResetCountdown(resetAtSeconds);
|
||||
if (resetAtISO) return formatResetCountdownISO(resetAtISO);
|
||||
return "";
|
||||
};
|
||||
|
||||
const [label, setLabel] = useState(getLabel);
|
||||
|
||||
useEffect(() => {
|
||||
setLabel(getLabel());
|
||||
const interval = setInterval(() => setLabel(getLabel()), 60_000);
|
||||
return () => clearInterval(interval);
|
||||
}, [resetAtSeconds, resetAtISO]);
|
||||
|
||||
if (!label) return null;
|
||||
|
||||
return (
|
||||
<Text className="text-xs text-neutral-500 dark:text-neutral-400">{label}</Text>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user