From dd215a8acc8a354dd132ccb9fa7a3a4acfd218ea Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Fri, 1 Jan 2021 13:58:34 +0530 Subject: [PATCH] Create Accident plugin --- src/plugins/Accident.js | 66 +++++++++++++++++++++++++++++++++++++++++ src/plugins/index.js | 4 ++- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/plugins/Accident.js diff --git a/src/plugins/Accident.js b/src/plugins/Accident.js new file mode 100644 index 0000000..a0aab44 --- /dev/null +++ b/src/plugins/Accident.js @@ -0,0 +1,66 @@ +import React, { useState, useEffect, useRef } from "react"; +import PropTypes from "prop-types"; +import { Box, Button, Heading, Text } from "grommet"; +import { Aid, Impact } from "grommet-icons"; + +function sendNotification(close) { + setTimeout(close, 2000); +} + +function Accident(props) { + const threshold = 20; + const [ time, setTime ] = useState(threshold); + const countRef = useRef(null); + + function decrementTime(time) { + if (time === 0) { + clearInterval(countRef.current); + sendNotification(props.close); + return 0; + } + return time - 1; + } + useEffect(() => { + countRef.current = setInterval(() => setTime(decrementTime), 1000); + return () => clearInterval(countRef.current); + }, []); + + function dismiss() { + clearTimeout(countRef.current); + props.close(); + } + return ( + + { + time === 0 ? + + : + } + { + time === 0 ? + "Calling Ambulance!" + :"Accident Detected!" + } + { + time === 0 ? "Calling Ambulance": + `To cancel calling the ambulance, press the button below. (${time})` + } +