From c409cdda168ca8a7d355133057f33afb5ea5c13d Mon Sep 17 00:00:00 2001 From: Sabari Ganesh <64348740+SabariGanesh-K@users.noreply.github.com> Date: Mon, 18 Oct 2021 10:12:11 +0530 Subject: [PATCH 1/2] Added a countdown component This is a functional component which fetches current time,next class time and displays a countdown of time left for next class --- src/components/CountDown/countdown.jsx | 91 ++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/components/CountDown/countdown.jsx diff --git a/src/components/CountDown/countdown.jsx b/src/components/CountDown/countdown.jsx new file mode 100644 index 0000000..0a759fc --- /dev/null +++ b/src/components/CountDown/countdown.jsx @@ -0,0 +1,91 @@ +import AsyncStorage from "@react-native-async-storage/async-storage"; +import React, { useEffect, useState } from "react"; +import ClassList from "../ClassList"; + +export default function CountDown(){ + + constructor(props) + { + super(props); + this.state = { datas : "",setCurrentDay:"",lecLists=[],nxt=0 }; + } + + function setDay(){ + var n = new Date().getDay(); + var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"] + this.setState({setCurrentDay:days[n]}) ; + this.setState({datas:ClassList(this.state.setCurrentDay)}); + } + + function setTimings(){ + datas(ClassList(setCurrentDay)) + + datas.forEach(async(l)=>{ + this.state.lecLists.push(l.from) + }) + } + + function renderCount(){ + + if (lecLists.length == 0){ + setDay() + setTimings() + renderCount() + } + else{ + const nextClassTime = this.state.nxt; + const currentTime = new Date().getTime() + + if (nextClassTime-currentTime > 0){ + const gap = nextClassTime-currentTime + } + else if (currentTime>nextClassTime && currentTime<=(nextClassTime+2400000)){ + const gap = 0; + + } + else{ + this.state.lecLists.pop() + this.setState({nxt:lecLists[0]}) + } + + const sec = 1000; + const min = sec*60; + const hr = min*60; + const day = hr*24; + + const daysMore = Math.floor(gap/day); + const hoursMore = Math.floor((gap%day)/hr); + const minsMore = Math.floor((gap%day)/min); + const secsMore = Math.floor((gap%day)/sec); + + return( +
+
+ You have a class in +
+
+ {daysMore}:{hoursMore}:{minsMore}:{secsMore} +
+
+ ) + } + + + + + } + + if (lecLists.length == 0){ + setDay() + setTimings() + } + else{ + + setInterval(renderCount(),1000) + + } + + + + +} \ No newline at end of file From b06bb3d88cce2edd949916104e037839951b1c50 Mon Sep 17 00:00:00 2001 From: Sabari Ganesh <64348740+SabariGanesh-K@users.noreply.github.com> Date: Mon, 18 Oct 2021 10:14:22 +0530 Subject: [PATCH 2/2] minor fix --- src/components/CountDown/countdown.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/CountDown/countdown.jsx b/src/components/CountDown/countdown.jsx index 0a759fc..141e992 100644 --- a/src/components/CountDown/countdown.jsx +++ b/src/components/CountDown/countdown.jsx @@ -18,7 +18,7 @@ export default function CountDown(){ } function setTimings(){ - datas(ClassList(setCurrentDay)) + datas.forEach(async(l)=>{ this.state.lecLists.push(l.from) @@ -88,4 +88,4 @@ export default function CountDown(){ -} \ No newline at end of file +}