-
Notifications
You must be signed in to change notification settings - Fork 0
Dev-328: View previous semesters offered #478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: preview
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import type { FC, ReactNode } from 'react'; | ||
| import { useEffect, useState } from 'react'; // to store the value of previous terms the course was offered in | ||
|
|
||
| import type { Course } from '@/types'; | ||
| import { getRatingBackground } from '@/utils/ratingColors'; | ||
| import { termsInverse } from '@/utils/terms'; | ||
|
|
||
| import styles from './DashboardSearchItem.module.css'; | ||
|
|
||
|
|
@@ -22,6 +24,27 @@ export const DashboardSearchItem: FC<DashboardSearchItemProps> = ({ | |
| } | ||
| }; | ||
|
|
||
| const [prevTerms, setPrevTerms] = useState<string[]>([]); | ||
|
|
||
| useEffect(() => { | ||
| // to display previous terms the course was offered in | ||
| if (!course.guid) { | ||
| return; | ||
| } | ||
| const courseId = course.guid.slice(4); | ||
| const currentTermCode = course.guid.slice(0, 4); | ||
| fetch(`/api/hoagie/course/terms/?course_id=${courseId}`) | ||
| .then((res) => res.json()) | ||
| .then((data: { terms: string[] }) => { | ||
| const prior = data.terms | ||
| .filter((code) => code <= currentTermCode) | ||
| .map((code) => termsInverse[code]) // convert term codes to readable format | ||
| .filter(Boolean); | ||
| setPrevTerms(prior); | ||
| }) | ||
| .catch(console.error); | ||
| }, [course.guid]); | ||
|
|
||
| return ( | ||
| <div className={styles.card} onClick={handleClick}> | ||
| <div className={styles.content}> | ||
|
|
@@ -36,6 +59,7 @@ export const DashboardSearchItem: FC<DashboardSearchItemProps> = ({ | |
| </div> | ||
| )} | ||
| </div> | ||
| {prevTerms.length > 0 && <div className={styles.prevTerms}>{prevTerms.join(', ')}</div>} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we using the .svg files?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no sorry I added these because I previously thought my task was to display the semester tags. I can remove these when I fix this pr. I'll get this fix in when I get clarification on how I should approach DashboardSearchItem firing a separate backend request |
||
| {children && <div className={styles.chipContainer}>{children}</div>} | ||
| </div> | ||
| </div> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, each DashboardSearchItem is firing a separate backend request. This would be bad for large queries (for example, look at the network requests under the developer console when you query 'c' in the search bar). Not sure what the best way to do this is, but one idea is to do these queries in DashboardSearchResults or Canvas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that if we were to do these in the initial search for the terms, the time it takes for the cards to load would increase. Having a quick loading for the cards then this happening next felt like it made sense, but I also understand the issue with a separate backend request. I can try to do that if we believe that would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try doing it in the initial search and see if we can make it fast enough. If we can't, then we can discuss what the alternative is.