2022-03-15 20:35:02 +01:00
|
|
|
import React from "react";
|
2022-05-10 16:39:05 +02:00
|
|
|
import { Text, Flex, Box } from "@chakra-ui/react";
|
2022-04-01 21:41:53 +02:00
|
|
|
import { useNuiEvent } from "../../hooks/useNuiEvent";
|
|
|
|
|
import { debugData } from "../../utils/debugData";
|
|
|
|
|
import { fetchNui } from "../../utils/fetchNui";
|
2022-03-15 20:35:02 +01:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
label: string;
|
|
|
|
|
duration: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
debugData([
|
|
|
|
|
{
|
|
|
|
|
action: "progress",
|
|
|
|
|
data: {
|
2022-03-19 12:57:49 +01:00
|
|
|
label: "Using Lockpick",
|
2022-03-15 20:35:02 +01:00
|
|
|
duration: 8000,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const Progressbar: React.FC = () => {
|
|
|
|
|
const [visible, setVisible] = React.useState(false);
|
|
|
|
|
const [label, setLabel] = React.useState("");
|
|
|
|
|
const [duration, setDuration] = React.useState(0);
|
2022-03-15 21:08:08 +01:00
|
|
|
const [cancelled, setCancelled] = React.useState(false);
|
2022-03-15 20:35:02 +01:00
|
|
|
|
|
|
|
|
const progressComplete = () => {
|
|
|
|
|
setVisible(false);
|
|
|
|
|
fetchNui("progressComplete");
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-15 21:08:08 +01:00
|
|
|
const progressCancel = () => {
|
|
|
|
|
setCancelled(true);
|
2022-06-14 19:18:24 +02:00
|
|
|
setVisible(false);
|
2022-03-15 21:08:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useNuiEvent("progressCancel", progressCancel);
|
|
|
|
|
|
2022-03-15 20:35:02 +01:00
|
|
|
useNuiEvent<Props>("progress", (data) => {
|
2022-03-15 21:08:08 +01:00
|
|
|
setCancelled(false);
|
2022-03-15 20:35:02 +01:00
|
|
|
setVisible(true);
|
|
|
|
|
setLabel(data.label);
|
|
|
|
|
setDuration(data.duration);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Flex
|
2022-04-16 13:04:22 +02:00
|
|
|
h="30%"
|
2022-03-15 20:35:02 +01:00
|
|
|
w="100%"
|
|
|
|
|
position="absolute"
|
|
|
|
|
bottom="0"
|
|
|
|
|
justifyContent="center"
|
|
|
|
|
alignItems="center"
|
|
|
|
|
>
|
2022-04-16 13:04:22 +02:00
|
|
|
<Box width={350}>
|
2022-05-10 16:39:05 +02:00
|
|
|
{visible && (
|
2022-04-16 13:04:22 +02:00
|
|
|
<Box
|
|
|
|
|
height={45}
|
|
|
|
|
bg="rgba(0, 0, 0, 0.6)"
|
|
|
|
|
textAlign="center"
|
2022-03-20 19:58:52 +01:00
|
|
|
borderRadius="sm"
|
|
|
|
|
boxShadow="lg"
|
2022-04-16 13:04:22 +02:00
|
|
|
overflow="hidden"
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
height={45}
|
|
|
|
|
onAnimationEnd={progressComplete}
|
|
|
|
|
sx={
|
|
|
|
|
!cancelled
|
|
|
|
|
? {
|
2022-05-10 16:39:05 +02:00
|
|
|
width: "0%",
|
2022-04-16 13:04:22 +02:00
|
|
|
backgroundColor: "green.400",
|
2022-05-10 16:39:05 +02:00
|
|
|
animation: "progress-bar linear",
|
|
|
|
|
animationDuration: `${duration}ms`,
|
2022-04-16 13:04:22 +02:00
|
|
|
}
|
|
|
|
|
: {
|
2022-06-14 19:18:24 +02:00
|
|
|
// Currently unused
|
2022-03-15 21:08:08 +01:00
|
|
|
width: "100%",
|
2022-05-10 16:39:05 +02:00
|
|
|
animationPlayState: "paused",
|
2022-03-15 21:08:08 +01:00
|
|
|
backgroundColor: "rgb(198, 40, 40)",
|
2022-04-16 13:04:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
<Text
|
|
|
|
|
fontFamily="Inter"
|
|
|
|
|
isTruncated
|
|
|
|
|
fontSize={22}
|
|
|
|
|
fontWeight="light"
|
|
|
|
|
position="absolute"
|
|
|
|
|
top="50%"
|
|
|
|
|
left="50%"
|
|
|
|
|
transform="translate(-50%, -50%)"
|
|
|
|
|
>
|
2022-03-20 19:58:52 +01:00
|
|
|
{label}
|
2022-04-16 13:04:22 +02:00
|
|
|
</Text>
|
|
|
|
|
</Box>
|
2022-05-10 16:39:05 +02:00
|
|
|
)}
|
2022-03-15 20:35:02 +01:00
|
|
|
</Box>
|
|
|
|
|
</Flex>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Progressbar;
|