Skip to content

Commit

Permalink
Add semesters to similar courses
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquelinecai committed Dec 4, 2024
1 parent cc95e22 commit 2f54589
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
29 changes: 27 additions & 2 deletions client/src/modules/Course/Components/SimilarCoursesCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import styles from '../Styles/SimilarCourses.module.css';
import axios from 'axios';
import { lastOfferedSems } from 'common/CourseCard';

type SimilarCourses = {
className: string;
Expand All @@ -14,11 +16,34 @@ export default function SimilarCoursesCard({
classNum,
tags
}: SimilarCourses): React.JSX.Element {
const [classSems, setClassSems] = useState('');
const getTagStyling = (tag: string) => {
if (tag.toLowerCase().includes('overall')) return styles.overall;
if (tag.toLowerCase().includes('higher')) return styles.higher;
if (tag.toLowerCase().includes('lower')) return styles.lower;
return styles.similar;
}

useEffect(() => {
const fetchClassSems = async () => {
try {
const response = await axios.post(`/api/courses/get-by-info`, {
number: classNum,
subject: classSub,
});

const course = response.data.result;
if (course) {
setClassSems(lastOfferedSems(course));
}
} catch (e) {
console.error('Unable to fetch class semesters');
}
};

fetchClassSems();
}, [classNum, classSub]);

return (
<div className={styles.card}>
<div className={styles.metrics}>
Expand All @@ -30,7 +55,7 @@ export default function SimilarCoursesCard({
{className}
</a>
<div className={styles.subtitle}>
{classSub.toUpperCase()} {classNum}
{classSub.toUpperCase()} {classNum}, {classSems}
</div>
</div>
<div className={styles.tags}>
Expand Down
4 changes: 4 additions & 0 deletions client/src/modules/Course/Styles/SimilarCourses.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
font-size: 12px;
}

.overall {
border-color: #0076FF;
}

.higher {
border-color: #ffa5a5;
}
Expand Down
9 changes: 7 additions & 2 deletions common/CourseCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export function lastOfferedSems(theClass) {
theClass.classSems.forEach((sem) => {
offered.add(semAbbriviationToWord(sem.slice(0, -2)));
});
// Array.from(offered).join(' ');
return Array.from(offered).join(', ');

const semOrder = ['Fall', 'Spring', 'Summer', 'Winter'];

const sortedSemesters = Array.from(offered).sort((a, b) => {
return semOrder.indexOf(a) - semOrder.indexOf(b);
});
return sortedSemesters.join(', ');
}

0 comments on commit 2f54589

Please sign in to comment.