diff --git a/app/(main)/compare/page.tsx b/app/(main)/compare/page.tsx index 08dd84b..934b266 100644 --- a/app/(main)/compare/page.tsx +++ b/app/(main)/compare/page.tsx @@ -1,4 +1,4 @@ -import { Card, LinkBtn } from '@/components/atoms'; +import { Btn, Card, LinkBtn } from '@/components/atoms'; import { CompareItem, FilterGroup, SearchBar } from '@/components/molecules'; import { BarChart } from '@/components/organisms'; import { @@ -8,6 +8,7 @@ import { } from '@/types'; import fetcher from '@/utils/fetcher'; import roundToTenth from '@/utils/round-to-tenth'; +import { EllipsisVerticalIcon, XMarkIcon } from '@heroicons/react/24/solid'; export default async function Page({ searchParams, @@ -108,12 +109,34 @@ export default async function Page({ return (
-
-
-
-

- Search and select professors and/or courses to compare -

+
+

Grade/Rating Analysis

+ + + +
+
+
+
+
+

Filters

+ + + +
+
@@ -149,30 +172,38 @@ export default async function Page({
-
- {professorStats.map((professor) => ( - - ))} - {courseStats.map((course) => ( - - ))} -
+ {professorStats.length + courseStats.length ? ( +
+ {professorStats.map((professor) => ( + + ))} + {courseStats.map((course) => ( + + ))} +
+ ) : ( +

+ No items selected. +
+ Search and select professors/courses to compare. +

+ )}

Rating Distribution

{ + const apiQueryParams = new URLSearchParams(); + apiQueryParams.set('query', currentQuery); + apiQueryParams.set('limit', '3'); + const { data, error, isLoading } = useSWR( + `/django/core/courses/search?${apiQueryParams.toString()}`, + ); + return { data, error, isLoading }; +}; + +const useProfessorsSearchResults = (currentQuery: string) => { + const apiQueryParams = new URLSearchParams(); + apiQueryParams.set('query', currentQuery); + apiQueryParams.set('limit', '3'); + + const { data, error, isLoading } = useSWR( + `/django/core/professors/search?${apiQueryParams.toString()}`, + ); + return { data, error, isLoading }; +}; + +interface StatusMessageProps { + isLoading: boolean; + error: Error | undefined; + data: ({ total_results: number } & unknown) | undefined; +} + +const StatusMessage: React.FC = ({ + isLoading, + error, + data, +}) => { + if (isLoading) { + return
  • Loading...
  • ; + } + if (error) { + return ( +
  • + Error: {error.message} +
  • + ); + } + if (!data || data.total_results === 0) { + return
  • No results found
  • ; + } + return null; +}; + +const CourseSearchResults: React.FC = () => { + const searchParams = useSearchParams(); + const currentOption = searchParams.get('compareOption') ?? 'professors'; + const currentQuery = searchParams.get('compareQuery') ?? ''; + const { data, error, isLoading } = useCoursesSearchResults(currentQuery); + return ( + + + {data && data.total_results > 0 + ? data.items.map((course, i) => ( +
  • + + + {course.department} {course.course_number} + + + {course.name} + + +
  • + )) + : null} +
    + ); +}; + +const ProfessorSearchResults: React.FC = () => { + const searchParams = useSearchParams(); + const currentOption = searchParams.get('compareOption') ?? 'professors'; + const currentQuery = searchParams.get('compareQuery') ?? ''; + const { data, error, isLoading } = useProfessorsSearchResults(currentQuery); + return ( + + + {data && data.total_results > 0 + ? data.items.map((professor, i) => ( +
  • + + + {professor.email} + + + {professor.name} + + +
  • + )) + : null} +
    + ); +}; + +export const CompareSearchBar: React.FC = () => { + const searchParams = useSearchParams(); + const currentOption = searchParams.get('compareOption') ?? 'professors'; + const currentQuery = searchParams.get('compareQuery') ?? ''; + return ( +
    + + + + + + {currentQuery ? ( + + + {currentOption === 'professors' ? ( + + ) : currentOption === 'courses' ? ( + + ) : null} + + + ) : null} +
    + ); +}; diff --git a/components/molecules/client/compare-search-bar/index.ts b/components/molecules/client/compare-search-bar/index.ts new file mode 100644 index 0000000..33b9887 --- /dev/null +++ b/components/molecules/client/compare-search-bar/index.ts @@ -0,0 +1,2 @@ +export { CompareSearchBar as default } from './component'; +export * from './component'; diff --git a/components/molecules/client/index.ts b/components/molecules/client/index.ts index f8c3abe..7ccf433 100644 --- a/components/molecules/client/index.ts +++ b/components/molecules/client/index.ts @@ -3,3 +3,4 @@ export * from './profile-btn'; export * from './nav-search-bar'; export * from './pagination-bar'; export * from './color-mode-picker'; +export * from './compare-search-bar'; diff --git a/components/molecules/compare-item/component.tsx b/components/molecules/compare-item/component.tsx new file mode 100644 index 0000000..995c454 --- /dev/null +++ b/components/molecules/compare-item/component.tsx @@ -0,0 +1,91 @@ +import { Card, LinkBtn, Stars } from '@/components/atoms'; +import { cn } from '@/utils/cn'; +import getEvaluation from '@/utils/get-evaluation'; +import { + ArrowPathIcon, + ClipboardDocumentListIcon, +} from '@heroicons/react/16/solid'; + +interface Props { + link: string; + id: string; + review?: number; + totalReviews: number; + avgGrade?: string | null; + takeAgainPercent?: number; +} + +export const CompareItem: React.FC = (props) => ( + + +
    +

    {props.id}

    +
    + {props.review ? ( +

    {props.review}

    + ) : ( +

    -

    + )} + +
    + +
    +

    + {props.totalReviews} Reviews +

    +
    +
    +
    +
    + +

    + Average Grade:{' '} + {props.avgGrade ? ( + + {props.avgGrade} + + ) : ( + - + )} +

    +
    +
    + +

    + Would Take Again:{' '} + {props.takeAgainPercent ? ( + + {props.takeAgainPercent}% + + ) : ( + - + )} +

    +
    +
    +
    +
    +); diff --git a/components/molecules/compare-item/index.ts b/components/molecules/compare-item/index.ts new file mode 100644 index 0000000..64a6f7c --- /dev/null +++ b/components/molecules/compare-item/index.ts @@ -0,0 +1,2 @@ +export {CompareItem as default} from './component'; +export * from './component'; diff --git a/components/molecules/index.ts b/components/molecules/index.ts index 99df5f3..8c587e9 100644 --- a/components/molecules/index.ts +++ b/components/molecules/index.ts @@ -2,3 +2,4 @@ export * from './filter-group'; export * from './param-select'; export * from './search-bar'; export * from './client'; +export * from './compare-item'; diff --git a/components/organisms/client/navbar/component.tsx b/components/organisms/client/navbar/component.tsx index 6d9dedc..673e0ce 100644 --- a/components/organisms/client/navbar/component.tsx +++ b/components/organisms/client/navbar/component.tsx @@ -93,6 +93,9 @@ export const Navbar: React.FC = () => { > Professors + + Compare +