Display num_interested on interested button

This commit is contained in:
Tanner Collin 2022-09-05 21:32:56 +00:00
parent 3c8a4ae7e4
commit 2d76aaf87d
2 changed files with 16 additions and 4 deletions

View File

@ -101,6 +101,7 @@ function NewClassTableCourse(props) {
const {course, classes, token, user, refreshUser} = props; const {course, classes, token, user, refreshUser} = props;
const [error, setError] = useState(false); const [error, setError] = useState(false);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [interested, setInterested] = useState(course.num_interested || 0);
const handleInterest = () => { const handleInterest = () => {
if (loading) return; if (loading) return;
@ -110,6 +111,7 @@ function NewClassTableCourse(props) {
.then(res => { .then(res => {
setError(false); setError(false);
refreshUser(); refreshUser();
setInterested(interested+1);
}) })
.catch(err => { .catch(err => {
console.log(err); console.log(err);
@ -139,14 +141,19 @@ function NewClassTableCourse(props) {
{user && {user &&
<div className='interest'> <div className='interest'>
{user.interests.filter(x => !x.satisfied_by).map(x => x.course).includes(course.id) ? {user.interests.filter(x => !x.satisfied_by).map(x => x.course).includes(course.id) ?
'Interested ✅' <Button
size='tiny'
color='green'
>
{interested} interested
</Button>
: :
<Button <Button
size='tiny' size='tiny'
loading={loading} loading={loading}
onClick={handleInterest} onClick={handleInterest}
> >
Interest&nbsp;+ {interested} interested
</Button> </Button>
} }
</div> </div>
@ -206,7 +213,7 @@ function NewClassTable(props) {
let sortedClasses = []; let sortedClasses = [];
let seenCourseIds = []; let seenCourseIds = [];
if (classes.length) { if (classes.length && courses.length) {
for (const clazz of classes) { for (const clazz of classes) {
const course_data = clazz.course_data; const course_data = clazz.course_data;
const course = sortedClasses.find(x => x?.course?.id === course_data?.id); const course = sortedClasses.find(x => x?.course?.id === course_data?.id);
@ -215,7 +222,7 @@ function NewClassTable(props) {
course.classes.push(clazz); course.classes.push(clazz);
} else { } else {
sortedClasses.push({ sortedClasses.push({
course: course_data, course: courses.find(x => x.id === course_data.id),
classes: [clazz], classes: [clazz],
}); });
seenCourseIds.push( seenCourseIds.push(

View File

@ -157,6 +157,11 @@ body {
margin-left: auto; margin-left: auto;
} }
.interest .ui.button {
padding-left: 0.5rem;
padding-right: 0.5rem;
}
.ui.tag.label { .ui.tag.label {
padding-left: 1rem; padding-left: 1rem;
padding-right: 0.5rem; padding-right: 0.5rem;