import React from "react"; import { Progress, ProgressLabel, Flex, Box, ScaleFade, } from "@chakra-ui/react"; import { useNuiEvent } from "../../hooks/useNuiEvent"; import { debugData } from "../../utils/debugData"; import { fetchNui } from "../../utils/fetchNui"; interface Props { label: string; duration: number; } debugData([ { action: "progress", data: { label: "Using Lockpick", duration: 8000, }, }, ]); const Progressbar: React.FC = () => { const [visible, setVisible] = React.useState(false); const [label, setLabel] = React.useState(""); const [duration, setDuration] = React.useState(0); const [cancelled, setCancelled] = React.useState(false); const progressComplete = () => { setVisible(false); fetchNui("progressComplete"); }; const progressCancel = () => { setCancelled(true); setTimeout(() => { setVisible(false); }, 2500); }; useNuiEvent("progressCancel", progressCancel); useNuiEvent("progress", (data) => { if (visible) return; setCancelled(false); setVisible(true); setLabel(data.label); setDuration(data.duration); }); return ( div:first-of-type": { animation: `progress-bar linear ${duration}ms`, borderRadius: "none", }, } : { "> div:first-of-type": { width: "100%", backgroundColor: "rgb(198, 40, 40)", }, } } > {label} ); }; export default Progressbar;