Skip to content

Commit

Permalink
Update course files
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquelinecai committed Feb 10, 2025
1 parent 33bdd4a commit 296cf89
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 72 deletions.
10 changes: 5 additions & 5 deletions client/src/modules/Course/Components/Course.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const Course = () => {
* Update state to conditionally render sticky bottom-right review button
*/
useEffect(() => {
function handleScroll() {
const handleScroll = () => {
setScrolled(window.scrollY >= 240);
}

Expand All @@ -117,7 +117,7 @@ export const Course = () => {
* Update screen width to conditionally render left/right panels
*/
useEffect(() => {
function handleResize() {
const handleResize = () => {
setScreenWidth(window.innerWidth);
}
window.addEventListener('resize', handleResize);
Expand All @@ -130,7 +130,7 @@ export const Course = () => {
* Fetches current course info and reviews and updates UI state
*/
useEffect(() => {
async function updateCurrentClass() {
const updateCurrentClass = async () => {
try {
const response = await axios.post(`/api/courses/get-by-info`, {
number,
Expand Down Expand Up @@ -168,7 +168,7 @@ export const Course = () => {
/**
* Sorts reviews based on selected filter
*/
function sortReviewsBy(event: React.ChangeEvent<HTMLSelectElement>) {
const sortReviewsBy = (event: React.ChangeEvent<HTMLSelectElement>) => {
const value = event.target.value;
if (value === 'helpful') {
setCourseReviews([...courseReviews].sort(sortByLikes));
Expand All @@ -182,7 +182,7 @@ export const Course = () => {
/**
* Save review information to session storage and begin redirect to auth
*/
function onSubmitReview(review: NewReview) {
const onSubmitReview = (review: NewReview) => {
Session.setPersistent({
review: review
});
Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/Course/Components/CourseReviews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const CourseReviews = ({
* Attempts to report review, and filters out the reported review locally
* @param reviewId: _id of review to report
*/
async function reportReview(reviewId: string) {
const reportReview = async (reviewId: string) => {
const response = await axios.post('/api/reviews/report', {
token: token,
id: reviewId
Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/Course/Components/Feedback.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* globals gtag */
export function courseVisited(classSub, classNum) {
export const courseVisited = (classSub, classNum) => {
gtag('event', 'Course Visited', {
eventCategory: 'Courses Visited',
eventLabel: classSub + classNum
Expand Down
56 changes: 23 additions & 33 deletions client/src/modules/Course/Components/PreviewReviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ type ReviewProps = {
- report button
- like button
*/
export default function PreviewReviewCard({
const PreviewReviewCard = ({
review,
isPreview,
isProfile
}: ReviewProps): React.JSX.Element {
}: ReviewProps): React.JSX.Element => {
const { isLoggedIn } = useAuthOptionalLogin();
const pending = isPreview && isProfile;
const [liked, setLiked] = useState<boolean>(false);
Expand All @@ -49,7 +49,7 @@ export default function PreviewReviewCard({
const [courseNum, setCourseNum] = useState<string>('');

/** Turns our date objects into a string form to render. */
function dateToString() {
const dateToString = () => {
if (!_review.date) return '';

const date = new Date(_review.date);
Expand All @@ -64,7 +64,7 @@ export default function PreviewReviewCard({
* Fetch the course information.
*/
useEffect(() => {
async function updateCourse() {
const updateCourse = async () => {
const response = await axios.post(`/api/courses/get-by-id`, {
courseId: _review.class
});
Expand All @@ -85,7 +85,7 @@ export default function PreviewReviewCard({
* 2. IF logged in user has liked the review or not and updates @liked state.
*/
useEffect(() => {
async function updateLiked() {
const updateLiked = async () => {
const response = await axios.post('/api/reviews/user-liked', {
id: _review._id,
token: getAuthToken()
Expand All @@ -98,34 +98,22 @@ export default function PreviewReviewCard({
}, [_review, isLoggedIn]);

/** Renders course name as well if on profile page */
function TitleAndProfessor() {
// list of professors (name1, name2, ..)
let professornames = '';
if (_review.professors && _review.professors.length > 0)
professornames += _review.professors.join(', ');
else professornames += 'Not Listed';

if (isProfile) {
return (
<>
<div className={previewstyle.coursetitle}>{courseTitle}</div>
<div className={previewstyle.classprofessor}>
{courseSub?.toUpperCase() +
' ' +
courseNum?.toUpperCase() +
' | ' +
professornames}
</div>
</>
);
} else {
return (
<div>
Professor <span className={styles.bold}>{professornames}</span>
const TitleAndProfessor = React.memo(() => {
let professornames = _review.professors?.join(', ') || 'Not Listed';

return isProfile ? (
<>
<div className={previewstyle.coursetitle}>{courseTitle}</div>
<div className={previewstyle.classprofessor}>
{courseSub?.toUpperCase() + ' ' + courseNum?.toUpperCase() + ' | ' + professornames}
</div>
);
}
}
</>
) : (
<div>
Professor <span className={styles.bold}>{professornames}</span>
</div>
);
});

/* SEE MORE -> SEE LESS logic for lengthier reviews */
const [expand, setExpand] = useState(false);
Expand All @@ -138,7 +126,7 @@ export default function PreviewReviewCard({
Fix the logic to not do this?
*/
useEffect(() => {
function handleResize() {
const handleResize = () => {
if (ref.current) {
setSeeMoreButton(ref.current.scrollHeight !== ref.current.clientHeight);
}
Expand Down Expand Up @@ -231,3 +219,5 @@ export default function PreviewReviewCard({
</div>
);
}

export default PreviewReviewCard;
20 changes: 10 additions & 10 deletions client/src/modules/Course/Components/RatingInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type RatingInputProps = {
* pointer or arrow keys. It is controlled with `value` and `setValue` and
* renders the value with "pills."
*/
export default function RatingInput({
const RatingInput = ({
name,
label,
value,
Expand All @@ -28,7 +28,7 @@ export default function RatingInput({
maxLabel,
className,
isOverall
}: RatingInputProps) {
}: RatingInputProps) => {
const [hoverIndex, setHoverIndex] = useState(value - 1);
const [color, setColor] = useState<string>('');

Expand All @@ -52,7 +52,7 @@ export default function RatingInput({
setColor(getColor(value));
}, [value]);

function handleKeyDown({ key }: any) {
const handleKeyDown = ({ key }: any) => {
if (key === 'ArrowLeft' && hoverIndex >= 1) {
buttonRefs[hoverIndex - 1].current.focus();
}
Expand Down Expand Up @@ -94,14 +94,12 @@ export default function RatingInput({
>
<div
className={`${styles.ratingButtonPill}
${
i >= value &&
i < hoverIndex + 1 &&
styles['ratingButtonPillHover' + color]
${i >= value &&
i < hoverIndex + 1 &&
styles['ratingButtonPillHover' + color]
}
${
i < hoverIndex + 1 &&
styles['ratingButtonPillSelected' + color]
${i < hoverIndex + 1 &&
styles['ratingButtonPillSelected' + color]
}
`}
/>
Expand All @@ -117,3 +115,5 @@ export default function RatingInput({
</div>
);
}

export default RatingInput;
26 changes: 14 additions & 12 deletions client/src/modules/Course/Components/ReviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ type ReviewProps = {
- report button
- like button
*/
export default function ReviewCard({
const ReviewCard = ({
review,
isPreview,
isProfile,
reportHandler
}: ReviewProps): React.JSX.Element {
}: ReviewProps): React.JSX.Element => {
const { isLoggedIn, signIn } = useAuthOptionalLogin();
const location = useLocation();

Expand All @@ -44,7 +44,7 @@ export default function ReviewCard({
const [courseNum, setCourseNum] = useState<string>('');

/** Turns our date objects into a string form to render. */
function dateToString() {
const dateToString = () => {
if (!_review.date) return '';

const date = new Date(_review.date);
Expand All @@ -58,7 +58,7 @@ export default function ReviewCard({
/**
* Shows user liked the review and updates DB count.
*/
async function likeReview() {
const likeReview = async () => {
if (!isLoggedIn) {
signIn('path:' + location.pathname);
}
Expand All @@ -77,7 +77,7 @@ export default function ReviewCard({
* Fetch the course information.
*/
useEffect(() => {
async function updateCourse() {
const updateCourse = async () => {
const response = await axios.post(`/api/courses/get-by-id`, {
courseId: _review.class
});
Expand All @@ -97,7 +97,7 @@ export default function ReviewCard({
* 2. IF logged in user has liked the review or not and updates @liked state.
*/
useEffect(() => {
async function updateLiked() {
const updateLiked = async () => {
const response = await axios.post('/api/reviews/user-liked', {
id: _review._id,
token: getAuthToken()
Expand All @@ -110,7 +110,7 @@ export default function ReviewCard({
}, [_review, isLoggedIn]);

/** Renders course name as well if on profile page */
function TitleAndProfessor() {
const TitleAndProfessor = () => {
// list of professors (name1, name2, ..)
let professornames = '';
if (_review.professors && _review.professors.length > 0)
Expand Down Expand Up @@ -150,7 +150,7 @@ export default function ReviewCard({
Fix the logic to not do this?
*/
useEffect(() => {
function handleResize() {
const handleResize = () => {
if (ref.current) {
setSeeMoreButton(ref.current.scrollHeight !== ref.current.clientHeight);
}
Expand Down Expand Up @@ -213,10 +213,10 @@ export default function ReviewCard({
<span className={styles.bold}>
{_review.major && _review.major.length !== 0
? _review.major.map((major, index) => (
<span key={index}>
{index > 0 && ', '} {major}
</span>
))
<span key={index}>
{index > 0 && ', '} {major}
</span>
))
: 'N/A'}
</span>
</div>
Expand Down Expand Up @@ -271,3 +271,5 @@ export default function ReviewCard({
</div>
);
}

export default ReviewCard;
13 changes: 4 additions & 9 deletions client/src/modules/Course/Components/ReviewModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ReviewModal = ({
professorOptions
}: Modal) => {
// Modal Logic
function closeModal() {
const closeModal = () => {
setReviewOpen(false);
}
// Content & Options
Expand Down Expand Up @@ -105,15 +105,10 @@ const ReviewModal = ({
}

// Handle Submission
function validReview(): boolean {
const professorChosen = selectedProfessors.length > 0;
const textWritten = reviewText.length > 5;
if (professorChosen && textWritten) return true;
return false;
}
const validReview = (): boolean => selectedProfessors.length > 0 && reviewText.length > 5;

// Called by onSubmitReview if the user should not see modal
function handleSubmitReview() {
const handleSubmitReview = () => {
if (validReview()) {
const newReview: NewReview = {
rating: overall,
Expand All @@ -130,7 +125,7 @@ const ReviewModal = ({
}

// Handle click of submit button
function onSubmitReview() {
const onSubmitReview = () => {
if (isLoggedIn) {
handleSubmitReview();
signIn('profile');
Expand Down
4 changes: 4 additions & 0 deletions client/src/modules/Course/Components/SimilarCoursesCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const SimilarCoursesCard: React.FC<SimilarCourses> = ({
}) => {
const [classSems, setClassSems] = useState('');

/*
Retrieves styling based on comparison in rating, difficulty, and workload
against target class
*/
const getTagStyling = (tag: string) => {
if (tag.toLowerCase().includes('overall')) return styles.overall;
if (tag.toLowerCase().includes('higher')) return styles.higher;
Expand Down
10 changes: 9 additions & 1 deletion server/src/course/course.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import axios from 'axios';
* Returns array of course ids that a given course is crosslisted with
*
* @param {string} reviewId: Mongo-generated id of review
* @returns true if operation was successful, false otherwise
* @returns array of course ids
*/
export const getCrossListOR = (course) => {
if (!course) {
Expand Down Expand Up @@ -56,6 +56,12 @@ export const getCourseByInfo = async ({
return course;
};

/**
* Returns array of reviews for all crosslisted classes of a given course
*
* @param {string} courseId: Mongo-generated id of course
* @returns array of reviews
*/
export const getReviewsCrossListOR = async ({
courseId
}: CourseIdRequestType) => {
Expand Down Expand Up @@ -95,11 +101,13 @@ export const getGlobalMetadata = async () => {
return global;
}

// testing function for preprocessing
export const getProcessedDescription = (text) => {
const processed = preprocess(text);
return processed;
}

// testing function for similarity algorithm
export const getSimilarity = async () => {
const result = await axios.get(
`https://classes.cornell.edu/api/2.0/search/classes.json?roster=FA24&subject=CS`
Expand Down
Loading

0 comments on commit 296cf89

Please sign in to comment.