From e3cdcd177d7ae64bd7675ccef232ec7117ec4617 Mon Sep 17 00:00:00 2001 From: butter-chicken27 Date: Sat, 9 Jan 2021 14:05:06 +0530 Subject: [PATCH 1/6] Toggle hall button added --- src/pages/Mess.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pages/Mess.js b/src/pages/Mess.js index 4622acd..e8ec599 100644 --- a/src/pages/Mess.js +++ b/src/pages/Mess.js @@ -94,6 +94,11 @@ function Mess({ Menu }) { const theme = useTheme(); const [hall, setHall] = useState('LDH'); + const toggleHall = () => { + if (hall === 'LDH') setHall('UDH'); + else setHall('LDH'); + }; + const getMeal = (meal) => { const listItems = Menu[hall][days[activeStep]][meal]; const additionalKey = `${hall} Additional`; @@ -142,8 +147,7 @@ function Mess({ Menu }) { ))} - - + Date: Sat, 9 Jan 2021 19:37:09 +0530 Subject: [PATCH 2/6] Data fetching for Bus data added --- src/App.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/App.js b/src/App.js index baa714c..c393577 100644 --- a/src/App.js +++ b/src/App.js @@ -64,6 +64,7 @@ const login = () => { function App() { const [user, loading, error] = useAuthState(firebase.auth()); // eslint-disable-line const [messData, setMessData] = useState({}); + const [busData, setBusData] = useState({}); // eslint-disable-line useEffect(() => { fetch(process.env.REACT_APP_MESS_API_ENDPOINT) @@ -77,6 +78,18 @@ function App() { }); }, [setMessData]); + useEffect(() => { + fetch(process.env.REACT_APP_BUS_API_ENDPOINT) + .then((res) => res.json()) + .then((res) => { + setBusData(res); + }) + .catch((err) => { + console.log(err); + setBusData(null); + }); + }, [setBusData]); + if (!user) { return ( + +

{location}

+ + ); } export default Bus; From 4d2b86988055c42623d0b811b5c24c213a9ad534 Mon Sep 17 00:00:00 2001 From: Tarun Ram Date: Thu, 14 Jan 2021 16:24:56 +0530 Subject: [PATCH 4/6] Finished Bus Page --- package-lock.json | 14 +++++ package.json | 1 + src/App.js | 11 +--- src/pages/Bus.css | 4 ++ src/pages/Bus.js | 147 ++++++++++++++++++++++++++++++++++++++-------- 5 files changed, 143 insertions(+), 34 deletions(-) create mode 100644 src/pages/Bus.css diff --git a/package-lock.json b/package-lock.json index 7a547b5..5efacd3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9572,6 +9572,11 @@ "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" }, + "memoize-one": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-5.1.1.tgz", + "integrity": "sha512-HKeeBpWvqiVJD57ZUAsJNm71eHTykffzcLZVYWiVfQeI1rJtuEaS7hQiEpWfVVk18donPwJEcFKIkCmPJNOhHA==" + }, "memory-fs": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz", @@ -12386,6 +12391,15 @@ "prop-types": "^15.6.2" } }, + "react-window": { + "version": "1.8.6", + "resolved": "https://registry.npmjs.org/react-window/-/react-window-1.8.6.tgz", + "integrity": "sha512-8VwEEYyjz6DCnGBsd+MgkD0KJ2/OXFULyDtorIiTz+QzwoP94tBoA7CnbtyXMm+cCeAUER5KJcPtWl9cpKbOBg==", + "requires": { + "@babel/runtime": "^7.0.0", + "memoize-one": ">=3.1.1 <6" + } + }, "read-pkg": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-3.0.0.tgz", diff --git a/package.json b/package.json index 2a0c4dc..7578a1f 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "react-firebase-hooks": "^2.2.0", "react-router-dom": "^5.2.0", "react-scripts": "3.4.3", + "react-window": "^1.8.6", "unfetcher": "^1.1.2" }, "scripts": { diff --git a/src/App.js b/src/App.js index c393577..0b3f616 100644 --- a/src/App.js +++ b/src/App.js @@ -111,31 +111,22 @@ function App() { - {' '} - {' '} - {' '} - + - {' '} - {' '} - {' '} - {' '} - {' '} - {' '} ); } diff --git a/src/pages/Bus.css b/src/pages/Bus.css new file mode 100644 index 0000000..72530e9 --- /dev/null +++ b/src/pages/Bus.css @@ -0,0 +1,4 @@ +.times-list { + max-height: 400px; + overflow: auto; +} diff --git a/src/pages/Bus.js b/src/pages/Bus.js index 0c87c77..a1837fb 100644 --- a/src/pages/Bus.js +++ b/src/pages/Bus.js @@ -1,17 +1,21 @@ import React, { useState } from 'react'; +import PropTypes from 'prop-types'; import Button from '@material-ui/core/Button'; import MenuItem from '@material-ui/core/MenuItem'; import Select from '@material-ui/core/Select'; +import Box from '@material-ui/core/Box'; +import { + Divider, List, ListItem, ListItemText, +} from '@material-ui/core'; -function Bus() { +import './Bus.css'; + +function Bus({ schedule }) { const [location, setLocation] = useState('LAB'); - const [week, setWeek] = useState('Weekday'); - const [open, setOpen] = React.useState(false); + const [isWeekend, setIsWeekend] = useState(false); + const [open, setOpen] = useState(false); const toggleWeek = () => { - if (week === 'Weekday') setWeek('Weekend'); - else { - setWeek('Weekday'); - } + setIsWeekend(!isWeekend); }; const handleClose = () => { setOpen(false); @@ -24,27 +28,122 @@ function Bus() { const handleChange = (event) => { setLocation(event.target.value); }; + + const makeTimeList = (direction) => { + if (direction === 'to') { + let times; + if (location === 'LINGAMPALLY') { + if (isWeekend) { + times = schedule.ToIITH.LINGAMPALLYW; + } else { + times = schedule.ToIITH.LINGAMPALLY; + } + } else { + times = schedule.ToIITH[location]; + } + + return times.map((time) => ( + <> + + {time} + + + + )); + } + if (direction === 'from') { + let times; + if (location === 'LINGAMPALLY') { + if (isWeekend) { + times = schedule.FromIITH.LINGAMPALLYW; + } else { + times = schedule.FromIITH.LINGAMPALLY; + } + } else { + times = schedule.FromIITH[location]; + } + + return times.map((time) => ( + <> + + {time} + + + + )); + } + + return ( + + Error + + ); + }; + + if (Object.keys(schedule).length === 0) { + return

Loading...

; + } + + if (schedule === null) { + return

Error

; + } + return (
- - + Lingampally + Sangareddy + ODF + Maingate + + + - Lingampally - Sangareddy - ODF - Maingate - -

{location}

+ +

+ IITH to + {location[0] + location.substr(1).toLowerCase()} +

+ {makeTimeList('to')} +
+ +

+ {location[0] + location.substr(1).toLowerCase()} + {' '} + to IITH +

+ {makeTimeList('from')} +
+
); } export default Bus; + +Bus.propTypes = { + schedule: PropTypes.objectOf(PropTypes.object), +}; + +Bus.defaultProps = { + schedule: {}, +}; From 98686ba8b205b062f324cefb7bfa9428048a3235 Mon Sep 17 00:00:00 2001 From: Tarun Ram Date: Thu, 14 Jan 2021 16:27:04 +0530 Subject: [PATCH 5/6] Updated .env.example --- .env.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 13ee593..42dde92 100644 --- a/.env.example +++ b/.env.example @@ -5,4 +5,5 @@ REACT_APP_FIREBASE_PROJECT_ID = REACT_APP_FIREBASE_STORAGE_BUCKET = REACT_APP_FIREBASE_MESSAGING_SENDER_ID = REACT_APP_FIREBASE_APP_ID = -REACT_APP_MESS_API_ENDPOINT = \ No newline at end of file +REACT_APP_MESS_API_ENDPOINT = +REACT_APP_BUS_API_ENDPOINT = From ec694c645941625f55e450421ae34379f061c894 Mon Sep 17 00:00:00 2001 From: Tarun Ram Date: Fri, 15 Jan 2021 14:15:03 +0530 Subject: [PATCH 6/6] Fixed Bug in Bus.js Check for empty object before null check was causing an error --- src/pages/Bus.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/Bus.js b/src/pages/Bus.js index a1837fb..a775dec 100644 --- a/src/pages/Bus.js +++ b/src/pages/Bus.js @@ -80,12 +80,12 @@ function Bus({ schedule }) { ); }; - if (Object.keys(schedule).length === 0) { - return

Loading...

; + if (schedule === null || schedule === undefined) { + return

Error

; } - if (schedule === null) { - return

Error

; + if (Object.keys(schedule).length === 0) { + return

Loading...

; } return (