Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making events recurring(daily/weekly) #24

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 34 additions & 31 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,14 @@ function App() {

const db = firebase.firestore();

const addCustomEvent = (eventName, startTime, endTime) => {
const newEvent = {
title: eventName,
start: new Date(startTime),
end: new Date(endTime),
};
localStorage.setItem(
customKey,
JSON.stringify([...customEvents, newEvent]),
);

const newEventList = makeEventList(aimsTimetable, [
...customEvents,
newEvent,
]);
const addCustomEvent = (events) => {
const newCustomEvents = customEvents.slice();
newCustomEvents.push(...events);
const newEventList = makeEventList(aimsTimetable, newCustomEvents);
localStorage.setItem(masterKey, JSON.stringify(newEventList));

localStorage.setItem(customKey, JSON.stringify(newCustomEvents));
setEventList(newEventList);
setCustomEvents((currentList) => [...currentList, newEvent]);
setCustomEvents(newCustomEvents);
};

const updateTT = () => {
Expand All @@ -93,20 +82,24 @@ function App() {
.then((doc) => {
if (doc.exists) {
const tt = {};

tt.identifiedCourses = doc.data().identifiedCourses;
tt.identifiedSegments = doc.data().identifiedSegments;
tt.identifiedSlots = doc.data().identifiedSlots;

if ('identifiedCourseNames' in doc.data()) {
tt.identifiedCourseNames = doc.data().identifiedCourseNames;
} else {
tt.identifiedCourseNames = null;
}

if (JSON.stringify(aimsTimetable) !== JSON.stringify(tt)) {
const newEventList = makeEventList(tt, customEvents);
console.log(newEventList);
localStorage.setItem(masterKey, JSON.stringify(newEventList));
setEventList(newEventList);
localStorage.setItem(aimsKey, JSON.stringify(tt));
setAimsTimetable(tt);
}
} else {
console.log('No such document');
}
})
.catch((err) => {
Expand Down Expand Up @@ -155,21 +148,31 @@ function App() {

if (userLoading) {
return (
<div
style={{
position: 'absolute',
left: '50%',
top: '50%',
transform: 'translate(-50%,-50%)',
}}
>
<CircularProgress />
</div>
<ThemeProvider theme={theme}>
<CssBaseline />
<Container>
<div
style={{
position: 'absolute',
left: '50%',
top: '50%',
transform: 'translate(-50%,-50%)',
}}
>
<CircularProgress />
</div>
</Container>
</ThemeProvider>
);
}

if (!user) {
return <Login />;
return (
<ThemeProvider theme={theme}>
<CssBaseline />
<Login />
</ThemeProvider>
);
}
if (window.location.pathname === '/iith-dashboard-pwa') window.location.href = '/';
return (
Expand Down
2 changes: 1 addition & 1 deletion src/makeEventList.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const segmentStartDates = [
'2021-11-18 00:00:00',
];

const segmentEndDates = [
export const segmentEndDates = [
'2021-09-01 11:59:59',
'2021-09-17 11:59:59',
'2021-10-07 11:59:59',
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import './Bus.css';

function Bus({ schedule, loading, error }) {
const [location, setLocation] = useState('LAB');
//const [isWeekend, setIsWeekend] = useState(false);
const isWeekend = false;
// const [isWeekend, setIsWeekend] = useState(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary comment kindly remove

const isWeekend = false;
const [open, setOpen] = useState(false);
// const toggleWeek = () => {
// setIsWeekend(!isWeekend);
Expand Down
87 changes: 82 additions & 5 deletions src/pages/TimeTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import DialogTitle from '@material-ui/core/DialogTitle';
import SnackBar from '@material-ui/core/Snackbar';
import MuiAlert from '@material-ui/lab/Alert';
import Box from '@material-ui/core/Box';
import Checkbox from '@material-ui/core/Checkbox';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import { segmentEndDates } from '../makeEventList';

import './TimeTable.css';

Expand Down Expand Up @@ -94,7 +97,6 @@ function TimeTable({ eventList, handleNewCustomEvent }) {
const handleEndChange = (event) => {
endTime = event.target.value;
};

const genNewEvent = () => {
if (!eventDate || !endTime || !startTime) {
alert('Start and End Times must be specified to create a new event');
Expand All @@ -104,14 +106,67 @@ function TimeTable({ eventList, handleNewCustomEvent }) {
// TODO: Ensure that end date is after start date, might mess up the Calendar library otherwise
const startDate = new Date(`${eventDate} ${startTime}:00`);
const endDate = new Date(`${eventDate} ${endTime}:00`);
const weekly = document.getElementById('weekly_recur');
const daily = document.getElementById('daily_recur');
const limitDate = new Date(`${segmentEndDates[5]}`);
if (startDate < endDate) {
handleNewCustomEvent(title, startDate, endDate);
const newCustomEvents = [];
if (weekly.checked) {
for (let i = 0; i < limitDate.getDate(); i += 1) {
newCustomEvents.push({
start: new Date(startDate),
end: new Date(endDate),
title,
});
startDate.setDate(startDate.getDate() + 7);
endDate.setDate(endDate.getDate() + 7);
}
} else if (daily.checked) {
for (let i = 0; i < limitDate.getDate(); i += 1) {
newCustomEvents.push({
start: new Date(startDate),
end: new Date(endDate),
title,
});
startDate.setDate(startDate.getDate() + 1);
endDate.setDate(endDate.getDate() + 1);
}
} else {
newCustomEvents.push({
start: new Date(startDate),
end: new Date(endDate),
title,
});
}
handleNewCustomEvent(newCustomEvents);
handleClose();
} else {
handleNewCustomEvent(title, endDate, startDate);
const newCustomEvents = [];
if (weekly.checked) {
for (let i = 0; i < limitDate.getDate(); i += 1) {
newCustomEvents.push({
start: new Date(endDate),
end: new Date(startDate),
title,
});
startDate.setDate(startDate.getDate() + 7);
endDate.setDate(endDate.getDate() + 7);
}
} else if (daily.checked) {
for (let i = 0; i < limitDate.getDate(); i += 1) {
newCustomEvents.push({
start: new Date(endDate),
end: new Date(startDate),
title,
});
startDate.setDate(startDate.getDate() + 1);
endDate.setDate(endDate.getDate() + 1);
}
} else {
newCustomEvents.push({ start: endDate, end: startDate, title });
}
}
handleClose();
};

return (
<div id="calendar-div">
<FullCalendar
Expand Down Expand Up @@ -215,6 +270,26 @@ function TimeTable({ eventList, handleNewCustomEvent }) {
}}
/>
</DialogContent>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
{/* <label htmlFor="daily_recur">Daily:
<input type="checkbox" id='daily_recur'/></label> */}
<FormControlLabel
control={
<Checkbox name="checkedB" color="primary" id="daily_recur" />
}
label="-Daily"
/>

{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
{/* <label htmlFor="weekly_recur">Weekly:
<input type="checkbox" id='weekly_recur'/></label> */}
<FormControlLabel
control={
<Checkbox name="checkedB" color="primary" id="weekly_recur" />
}
label="-Weekly"
/>

<DialogActions>
<Button
onClick={genNewEvent}
Expand All @@ -230,12 +305,14 @@ function TimeTable({ eventList, handleNewCustomEvent }) {
}

TimeTable.propTypes = {
// eslint-disable-next-line
eventList: PropTypes.arrayOf(PropTypes.object),
handleNewCustomEvent: PropTypes.func,
};

TimeTable.defaultProps = {
eventList: [],
// eslint-disable-next-line
handleNewCustomEvent: () => {
alert('Error, please try again later');
},
Expand Down