-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add courses page ordered by departments
- Loading branch information
1 parent
7aac34a
commit f58ba49
Showing
2 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Card } from '@/components/atoms'; | ||
import { CoursesSearchResponse } from '@/types'; | ||
import Link from 'next/link'; | ||
|
||
export default async function Page() { | ||
const data: CoursesSearchResponse = await fetch( | ||
process.env.BASE_API_URL + '/core/courses/search', | ||
).then((resp) => resp.json()); | ||
|
||
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
const map: Map<string, { department: string; count: number }[]> = new Map(); | ||
for (const letter of letters) { | ||
map.set(letter, []); | ||
} | ||
|
||
data.filters.departments.forEach(({ department, count }) => | ||
map.get(department[0])?.push({ department, count }), | ||
); | ||
|
||
const components: { | ||
letter: string; | ||
departments: { department: string; count: number }[]; | ||
}[] = []; | ||
map.forEach((value, key) => { | ||
if (value.length > 0) { | ||
components.push({ letter: key, departments: value }); | ||
} | ||
}); | ||
|
||
return ( | ||
<main className="mx-auto w-full max-w-content-width px-md"> | ||
<div className="py-lg text-h2-mobile lg:text-h2-desktop">Courses</div> | ||
|
||
<div className="flex flex-col gap-[20px]"> | ||
{components.map(({ letter, departments }) => ( | ||
<Card key={letter} className="flex flex-col gap-[20px] p-[20px]"> | ||
<div className="flex flex-col items-center"> | ||
<span className="text-h3-mobile lg:text-h3-desktop"> | ||
{letter} | ||
</span> | ||
<span className="text-text"> | ||
{departments.length} Departments | ||
</span> | ||
</div> | ||
<div className="flex flex-row flex-wrap justify-center gap-[20px]"> | ||
{departments.map((department) => ( | ||
<Card className="items-center" key={department.department}> | ||
<Link | ||
href={`/courses/search?department=${department.department}`} | ||
className="flex w-[250px] flex-row items-center justify-between px-md py-md animation hover:bg-[rgb(var(--color-secondary)/0.15)] focus:bg-[rgb(var(--color-secondary)/0.15)]" | ||
> | ||
<span className="overflow-ellipsis text-p font-bold"> | ||
{department.department} | ||
</span> | ||
<span className="overflow-ellipsis text-small-lg text-neutral"> | ||
{department.count} Courses | ||
</span> | ||
</Link> | ||
</Card> | ||
))} | ||
</div> | ||
</Card> | ||
))} | ||
</div> | ||
</main> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.