From 44491b92df8d6feccb68b227d6fbb8fcd34144d6 Mon Sep 17 00:00:00 2001 From: Luke Date: Tue, 15 Mar 2022 15:42:54 +0100 Subject: [PATCH] feat(nui): Circle progressbar --- web/src/components/App.tsx | 3 + web/src/components/CircleProgressbar.tsx | 80 ++++++++++++++++++++++++ web/src/index.css | 9 +++ web/src/index.tsx | 8 +++ 4 files changed, 100 insertions(+) create mode 100644 web/src/components/CircleProgressbar.tsx diff --git a/web/src/components/App.tsx b/web/src/components/App.tsx index c9299c5..fe0c6e2 100644 --- a/web/src/components/App.tsx +++ b/web/src/components/App.tsx @@ -1,8 +1,11 @@ import Notifications from "./Notifications"; +import CircleProgressbar from "./CircleProgressbar"; +import { CircularProgress } from "@chakra-ui/react"; const App: React.FC = () => { return ( <> + ); diff --git a/web/src/components/CircleProgressbar.tsx b/web/src/components/CircleProgressbar.tsx new file mode 100644 index 0000000..5b2ad87 --- /dev/null +++ b/web/src/components/CircleProgressbar.tsx @@ -0,0 +1,80 @@ +import React from "react"; +import { + CircularProgress, + CircularProgressLabel, + Flex, + ScaleFade, +} from "@chakra-ui/react"; +import { useNuiEvent } from "../hooks/useNuiEvent"; +import { debugData } from "../utils/debugData"; +import { fetchNui } from "../utils/fetchNui"; + +interface Props { + duration: number; +} + +debugData([ + { + action: "circleProgress", + data: { + duration: 8000, + }, + }, +]); + +const CircleProgressbar: React.FC = () => { + const [visible, setVisible] = React.useState(false); + const [progressDuration, setProgressDuration] = React.useState(0); + const [value, setValue] = React.useState(0); + + const progressComplete = () => { + setVisible(false); + fetchNui("progressComplete"); + }; + + useNuiEvent("circleProgress", (data) => { + if (visible) return; + setVisible(true); + setValue(0); + setProgressDuration(data.duration); + const onePercent = data.duration * 0.01; + const updateProgress = setInterval(() => { + setValue((previousValue) => { + const newValue = previousValue + 1; + newValue >= 100 && clearInterval(updateProgress); + return newValue; + }); + }, onePercent); + }); + + return ( + + + + {value}% + + + + ); +}; + +export default CircleProgressbar; diff --git a/web/src/index.css b/web/src/index.css index 98c5ea6..9cbfc57 100644 --- a/web/src/index.css +++ b/web/src/index.css @@ -17,3 +17,12 @@ code { font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace; } + +@keyframes progress { + 0% { + stroke-dasharray: 0, 264; + } + 100% { + stroke-dasharray: 264, 0; + } +} diff --git a/web/src/index.tsx b/web/src/index.tsx index cc36980..d097f2d 100644 --- a/web/src/index.tsx +++ b/web/src/index.tsx @@ -5,6 +5,14 @@ import App from "./components/App"; import { VisibilityProvider } from "./providers/VisibilityProvider"; import { ChakraProvider } from "@chakra-ui/react"; import { theme } from "./theme"; +import { debugData } from "./utils/debugData"; + +debugData([ + { + action: "setVisible", + data: true, + }, +]); ReactDOM.render(