diff --git a/src/pages/Popup/components/AlarmUp.jsx b/src/pages/Popup/components/AlarmUp.jsx index ff002d1..f7b0266 100644 --- a/src/pages/Popup/components/AlarmUp.jsx +++ b/src/pages/Popup/components/AlarmUp.jsx @@ -11,6 +11,11 @@ import Zoom from '@material-ui/core/Zoom'; import PersonAddIcon from '@material-ui/icons/PersonAdd'; import CloseIcon from '@material-ui/icons/Close'; import DoneIcon from '@material-ui/icons/Done'; +import Accordion from '@material-ui/core/Accordion'; +import AccordionSummary from '@material-ui/core/AccordionSummary'; +import AccordionDetails from '@material-ui/core/AccordionDetails'; +import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; +import Typography from '@material-ui/core/Typography'; import { getAllDataFromStorage, @@ -23,42 +28,100 @@ class Alarmview extends Component { constructor() { super(); this.state = { - alarms: [], + listOfTodayAlarms: [], + listOfLaterAlarms: [], + listOfTomorrowAlarms: [], + expanded: false, }; + this.accordion1Ref = React.createRef(); + this.accordion2Ref = React.createRef(); + this.accordion3Ref = React.createRef(); } async componentDidMount() { let data = await getAllDataFromStorage(); console.log(data); var alarms = await new Promise((resolve) => chrome.alarms.getAll(resolve)); - var setalarms = []; + const todayAlarms = []; + const tomorrowAlarms = []; + const laterAlarms = []; + let tomorrowAlarmsListCounter = 0; + let todayAlarmsListCounter = 0; + let laterAlarmsListCounter = 0; alarms.sort(function (a, b) { return a.scheduledTime - b.scheduledTime; }); + + var time = new Date(); + let todayTime = new Date(time.getTime()); + let tomorrowTime = new Date(time.setDate(time.getDate() + 1)); + console.log(alarms); for (let i = 0; i < alarms.length; i++) { - var time = new Date(); time.setTime(alarms[i].scheduledTime); - time = time.toLocaleString('en-US', {day:'numeric', month:"numeric", year:'numeric', hour:'numeric', minute:'numeric', hour12:true}) - setalarms.push({ - time: time, - id: i, - name: alarms[i].name, - data: data[alarms[i].name].course, - status: data[alarms[i].name].status, - custom: data[alarms[i].name].course.type === 'custom', - }); + console.log(todayTime.toLocaleDateString(), time.toLocaleString()); + // time = time.toLocaleString(); + // Checking for today + if (time.toLocaleDateString() === todayTime.toLocaleDateString()) { + todayAlarms.push({ + time: time.toLocaleString(), + id: todayAlarmsListCounter, + name: alarms[i].name, + data: data[alarms[i].name].course, + status: data[alarms[i].name].status, + custom: data[alarms[i].name].course.type === 'custom', + alarmDayCategoryList: 'listOfTodayAlarms', + }); + todayAlarmsListCounter++; + } else if ( + time.toLocaleDateString() === tomorrowTime.toLocaleDateString() + ) { + tomorrowAlarms.push({ + time: time.toLocaleString(), + id: tomorrowAlarmsListCounter, + name: alarms[i].name, + data: data[alarms[i].name].course, + status: data[alarms[i].name].status, + custom: data[alarms[i].name].course.type === 'custom', + alarmDayCategoryList: 'listOfTomorrowAlarms', + }); + tomorrowAlarmsListCounter++; + } else { + laterAlarms.push({ + time: time.toLocaleString(), + id: laterAlarmsListCounter, + name: alarms[i].name, + data: data[alarms[i].name].course, + status: data[alarms[i].name].status, + custom: data[alarms[i].name].course.type === 'custom', + alarmDayCategoryList: 'listOfLaterAlarms', + }); + laterAlarmsListCounter++; + } + // setalarms.push({ + // time: time, + // id: i, + // name: alarms[i].name, + // data: data[alarms[i].name].course, + // status: data[alarms[i].name].status, + // custom: data[alarms[i].name].course.type === 'custom', + // }); } - this.setState({ alarms: setalarms }); + this.setState({ + listOfLaterAlarms: laterAlarms, + listOfTomorrowAlarms: tomorrowAlarms, + listOfTodayAlarms: todayAlarms, + }); } trunc(string, num) { return string.length > num ? `${string.slice(0, num)}..` : string; } - updatestatus = async (alarm_id) => { - var state = this.state.alarms; + updatestatus = async ({ alarm_id, alarmsList, alarmDayCategoryList }) => { + var state = alarmsList; + // console.log(alarmsList); state[alarm_id].status = !state[alarm_id].status; - this.setState({ alarms: state }); + this.setState({ [alarmDayCategoryList]: state }); let data = await getAllDataFromStorage(); var key = state[alarm_id].name; var val = data[state[alarm_id].name]; @@ -86,14 +149,38 @@ class Alarmview extends Component { console.log(alarm); return alarm.custom ? `${alarm.data.Name}` : `${alarm.data.A}`; }; + checkHeightOfAccodion = (height) => { + return { + height: height > 147 ? '147px' : 'auto', + }; + }; + getAlarmsList = (listOfAlarms) => { + const { + expanded, + accordian1Height, + accordion2Height, + accordion3Height, + } = this.state; + let listStyle = null; + + if (expanded === 'panel1') { + listStyle = this.checkHeightOfAccodion(accordian1Height); + } else if (expanded === 'panel2') { + listStyle = this.checkHeightOfAccodion(accordion2Height); + } else { + listStyle = this.checkHeightOfAccodion(accordion3Height); + } - render() { return ( -