From 5da382ee355a95b154859768e4447af6540f55e0 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 16 Mar 2020 04:45:00 +0000 Subject: [PATCH] Add list of upcoming classes on same day --- webclient/src/InstructorClasses.js | 55 +++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/webclient/src/InstructorClasses.js b/webclient/src/InstructorClasses.js index c6b3670..6d67495 100644 --- a/webclient/src/InstructorClasses.js +++ b/webclient/src/InstructorClasses.js @@ -202,7 +202,7 @@ export function InstructorClassAttendance(props) { : } @@ -325,6 +325,8 @@ export function InstructorClassList(props) { const [error, setError] = useState(false); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); + const [classes, setClasses] = useState([]); + const [sameClasses, setSameClasses] = useState(false); const handleSubmit = (e) => { if (loading) return; @@ -347,6 +349,22 @@ export function InstructorClassList(props) { }); }; + useEffect(() => { + requester('/sessions/', 'GET', token) + .then(res => { + setClasses(res.results.filter(x => !x.is_cancelled)); + }) + .catch(err => { + console.log(err); + }); + }, []); + + useEffect(() => { + setSameClasses(classes.filter(x => + moment.utc(x.datetime).tz('America/Edmonton').isSame(input.datetime, 'day') + )); + }, [input.datetime]); + return (
Instructor Panel
@@ -354,15 +372,36 @@ export function InstructorClassList(props) { {!open && success &&

Added! View the class.

} {open ? -
-
Add a Class
+ + + +
Add a Class
- + - - Submit - - + + Submit + + +
+ + {!!input.datetime && +
+
Upcoming Classes That Day
+ + {sameClasses.length ? + sameClasses.map(x => +

+ {moment.utc(x.datetime).tz('America/Edmonton').format('LT')} — {x.course_name} +

+ ) + : +

None

+ } +
+ } +
+
: