-
Notifications
You must be signed in to change notification settings - Fork 28
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
Bug fix: Subject cards now say (Not offered) if "Show in Session" filter button is used #241
Changes from 6 commits
9e08a4a
bf6765f
9514a29
b352f09
4995f8e
889a272
46d7bcd
b61bac6
8a88a01
98184c0
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,8 +1,8 @@ | ||
import { LinkBox } from '@chakra-ui/layout'; | ||
import { LinkBox, Box } from '@chakra-ui/layout'; | ||
import { Collapse } from '@chakra-ui/transition'; | ||
import { Link, useLocation, useSearchParams } from 'react-router-dom'; | ||
|
||
import { KualiSubject } from 'lib/fetchers'; | ||
import { InSessionSubject } from 'lib/types'; | ||
|
||
import { Card } from './Card'; | ||
|
||
|
@@ -15,7 +15,7 @@ type SubjectsListProps = { | |
* Subject to be displayed | ||
* EX) SENG 265 -> SENG | ||
*/ | ||
subjects: KualiSubject[]; | ||
subjects: InSessionSubject[]; | ||
}; | ||
|
||
export function SubjectsList({ term, subjects }: SubjectsListProps): JSX.Element { | ||
|
@@ -27,18 +27,28 @@ export function SubjectsList({ term, subjects }: SubjectsListProps): JSX.Element | |
|
||
return ( | ||
<Collapse in style={{ overflowY: 'scroll' }}> | ||
{subjects.map((subject, index) => ( | ||
<LinkBox | ||
as={Link} | ||
to={{ | ||
pathname: `/${route}/${term}/${subject.subject}`, | ||
search: pid ? `?pid=${pid}` : undefined, | ||
}} | ||
key={index} | ||
> | ||
<Card subject={subject.subject} title={subject.title} /> | ||
</LinkBox> | ||
))} | ||
{subjects.map((subject, index) => { | ||
if (subject.inSession) { | ||
return ( | ||
<LinkBox | ||
as={Link} | ||
to={{ | ||
pathname: `/${route}/${term}/${subject.subject}`, | ||
search: pid ? `?pid=${pid}` : undefined, | ||
}} | ||
key={index} | ||
> | ||
<Card subject={subject.subject} inSessionSubject={subject.inSession} title={subject.title} /> | ||
</LinkBox> | ||
); | ||
} else { | ||
return ( | ||
<Box key={index}> | ||
<Card subject={subject.subject} inSessionSubject={subject.inSession} title={subject.title} /> | ||
</Box> | ||
); | ||
} | ||
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. This can use tenary conditional so you can remove the |
||
})} | ||
</Collapse> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { Center, Box, Flex, Heading, HStack, Spinner } from '@chakra-ui/react'; | |
import { Route, Routes } from 'react-router'; | ||
|
||
import { Course, Term, useGetCourses, useSubjects } from 'lib/fetchers'; | ||
import { InSessionSubject } from 'lib/types'; | ||
|
||
import { CoursesList } from '../components/CoursesList'; | ||
import { CustomHits } from '../components/SearchResults'; | ||
|
@@ -48,13 +49,29 @@ export function SidebarContainer({ searchQuery, term }: SidebarContainerProps): | |
term: term as Term, | ||
queryParams: { in_session: filter }, | ||
}); | ||
// re assign the type of subjects so inSession property is available | ||
const inSessionSubjects: InSessionSubject[] | null = subjects; | ||
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. This isn't required since you're mapping against the original thing. You can just return a |
||
|
||
const loading = subjectsLoading || coursesLoading; | ||
|
||
// sorts the list of subjects alphabetically | ||
const sortedSubjects = useMemo(() => subjects?.sort((a, b) => (a.subject > b.subject ? 1 : -1)), [subjects]); | ||
const parsedCourses = useMemo(() => computeParsedCourses(courses), [courses]); | ||
|
||
// sorts the list of subjects alphabetically | ||
const sortedSubjects = useMemo( | ||
() => | ||
inSessionSubjects | ||
?.sort((a, b) => (a.subject > b.subject ? 1 : -1)) | ||
.map((subject) => { | ||
subject.inSession = true; | ||
//checks if subject is not in session | ||
if (filter && !parsedCourses[subject.subject]) { | ||
subject.inSession = false; | ||
} | ||
return subject; | ||
}), | ||
[filter, inSessionSubjects, parsedCourses] | ||
); | ||
|
||
const handleFilter = (s: boolean) => { | ||
setFilter(s); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { KualiSubject } from './fetchers'; | ||
|
||
export interface KualiSubjectInSession { | ||
inSession?: boolean; | ||
} | ||
export type InSessionSubject = KualiSubject & KualiSubjectInSession; | ||
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. This can be combined into one type declaration. Also, I would suggest not calling it |
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.
Can this be combined and just conditionally pass in the props?