import React, { useState, useEffect } from "react" import { DEFAULT_THEME, Paper, Text, Progress } from '@mantine/core' import { fetchNui } from "../utils/fetchNui" import { useNuiEvent } from "../hooks/useNuiEvent" const Timer: React.FC = () => { const theme = DEFAULT_THEME const [time, setTime] = useState(0) const [maxTime, setMaxTime] = useState(60) const [position, setPosition] = useState('') const [label, setLabel] = useState('') useNuiEvent('timer', (data) => { setLabel(data.label) setTime(data.time) setMaxTime(data.time) setPosition(data.position) }) useEffect(() => { if (time > 0) { const timerInterval = setInterval(() => { setTime((prevTime) => { if (prevTime <= 1) { clearInterval(timerInterval) fetchNui('finishTimer') return 0 } return prevTime - 1 }) }, 1000) return () => clearInterval(timerInterval) } }, [time]) return (
{label}: {time}s
) } export default Timer