From 517854198fe10c7db17cb421eb0adcf96a0d5579 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Tue, 24 May 2022 05:02:15 +0000 Subject: [PATCH] Add interest button and tags to course page --- webclient/src/App.js | 2 +- webclient/src/Courses.js | 42 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/webclient/src/App.js b/webclient/src/App.js index 61befa9..04eba00 100644 --- a/webclient/src/App.js +++ b/webclient/src/App.js @@ -294,7 +294,7 @@ function App() { - + diff --git a/webclient/src/Courses.js b/webclient/src/Courses.js index b02e7bd..f29490a 100644 --- a/webclient/src/Courses.js +++ b/webclient/src/Courses.js @@ -140,9 +140,25 @@ export function Courses(props) { export function CourseDetail(props) { const [course, setCourse] = useState(false); const [error, setError] = useState(false); - const { token, user } = props; + const [loading, setLoading] = useState(false); + const { token, user, refreshUser } = props; const { id } = useParams(); + const handleInterest = () => { + if (loading) return; + setLoading(true); + const data = { course: course.id }; + requester('/interest/', 'POST', token, data) + .then(res => { + setError(false); + refreshUser(); + }) + .catch(err => { + console.log(err); + setError(true); + }); + }; + useEffect(() => { requester('/courses/'+id+'/', 'GET', token) .then(res => { @@ -163,6 +179,30 @@ export function CourseDetail(props) {
{course.name}
+

+ {!!course.tags && course.tags.split(',').map(name => + + )} +

+ + {user && +

+ {user.interests.filter(x => !x.satisfied_by).map(x => x.course).includes(course.id) ? + 'Interested ✅' + : + + } +

+ } + {isInstructor(user) && }