Display num_interested on interested button
This commit is contained in:
parent
3c8a4ae7e4
commit
2d76aaf87d
|
@ -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 +
|
{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(
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user