Skip to content
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

Catalog dashboard page updates #760

Merged
merged 11 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
border-radius: 8px;
background-color: var(--foreground-color);
flex-shrink: 0;
.error {
color: var(--paragraph-color);
text-align: center;
margin-top: 46px;
font-size: 14px;
}
}

.header {
Expand Down Expand Up @@ -48,4 +54,4 @@
color: var(--paragraph-color);
margin-top: 8px;
}
}
}
182 changes: 164 additions & 18 deletions apps/frontend/src/app/Catalog/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,126 @@ import { Dispatch, SetStateAction } from "react";
import {
ArrowSeparateVertical,
BookmarkSolid,
Calendar,
Collapse,
Expand,
Search,
} from "iconoir-react";

import { Button, Container, IconButton, Tooltip } from "@repo/theme";
import { DropdownMenu } from "@repo/theme";

import Carousel from "@/components/Carousel";
import CarouselClass from "@/components/CarouselClass";
import { useReadUser } from "@/hooks/api";
import { ITerm } from "@/lib/api";
import { getRecents } from "@/lib/recents";

import Carousel from "./Carousel";
import styles from "./Dashboard.module.scss";

interface DashboardProps {
term: ITerm | null | undefined;
termList: ITerm[] | undefined;
changeTerm: React.Dispatch<React.SetStateAction<ITerm | null>>;
onSelect: (subject: string, courseNumber: string, number: string) => void;
expanded: boolean;
setExpanded: Dispatch<SetStateAction<boolean>>;
setOpen: Dispatch<SetStateAction<boolean>>;
}

function getOrdinalSuffix(day: number): string {
if (day > 3 && day < 21) return "th"; // applies to 11-20
switch (day % 10) {
case 1:
return "st";
case 2:
return "nd";
case 3:
return "rd";
default:
return "th";
}
}

function formatDate(date: Date): string {
const monthNames = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];

const day = date.getDate();
const month = monthNames[date.getMonth()];
const ordinalSuffix = getOrdinalSuffix(day);

return `${month} ${day}${ordinalSuffix}`;
}

export default function Dashboard({
term,
termList,
changeTerm,
onSelect,
expanded,
setExpanded,
setOpen,
}: DashboardProps) {
const { data: user, loading: userLoading } = useReadUser();

if (!term) return <></>;

const recents = getRecents().filter(
(v) => v.semester == term.semester && v.year == term.year
);

return (
<div className={styles.root}>
<Container size="sm">
<div className={styles.header}>
<Button>
<ArrowSeparateVertical />
Switch terms
</Button>
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild>
<Button>
<ArrowSeparateVertical />
Switch terms
</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content sideOffset={5}>
{termList ? (
termList
.filter(
({ year, semester }, index) =>
index ===
termList.findIndex(
(term) =>
term.semester === semester && term.year === year
)
)
.map((t) => {
return (
<DropdownMenu.Item
key={`${t.semester} ${t.year}`}
onClick={() => {
changeTerm(t);
}}
>
{t.semester} {t.year}
</DropdownMenu.Item>
);
})
) : (
<></>
)}
<DropdownMenu.Arrow style={{ fill: "var(--foreground-color)" }} />
</DropdownMenu.Content>
</DropdownMenu.Root>
<div className={styles.toggle}>
<Button variant="solid" onClick={() => setOpen(false)}>
Search
Expand All @@ -45,23 +135,79 @@ export default function Dashboard({
</Tooltip>
</div>
</div>
<p className={styles.heading}>Summer 2024</p>
<p className={styles.paragraph}>March 20th through August 9th</p>
<Carousel title="Recently viewed" Icon={<Search />}>
<div className={styles.card}></div>
<div className={styles.card}></div>
<div className={styles.card}></div>
</Carousel>
<Carousel title="Upcoming events" Icon={<Calendar />} to="/semesters">
<p className={styles.heading}>
{term.semester} {term.year}
</p>
{term.startDate && term.endDate ? (
<p className={styles.paragraph}>
{formatDate(new Date(term.startDate))} through{" "}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using a custom formatDate function, I've already installed and imported Moment.js elsewhere that you can use:

{moment(term.startDate).format("MMMM Do")}

{formatDate(new Date(term.endDate!))}
</p>
) : (
<></>
)}
{/* <Carousel title="Upcoming events" Icon={<Calendar />} to="/semesters">
<div className={styles.card}></div>
<div className={styles.card}></div>
<div className={styles.card}></div>
</Carousel>
</Carousel> */}
<Carousel title="Bookmarked" Icon={<BookmarkSolid />} to="/account">
<div className={styles.card}></div>
<div className={styles.card}></div>
<div className={styles.card}></div>
{userLoading || !user ? (
<div className={styles.card}>
<div className={styles.error}>Sign in to bookmark classes</div>
</div>
) : user?.bookmarkedClasses.length == 0 ? (
<div className={styles.card}>
<div className={styles.error}>No bookmarked classes</div>
</div>
) : (
user?.bookmarkedClasses
.filter(
(c) =>
!term || (c.year == term.year && c.semester == term.semester)
)
.map((c, i) => {
return (
<div key={i} className={styles.card}>
<CarouselClass
onSelect={onSelect}
subject={c.subject}
year={c.year}
semester={c.semester}
courseNumber={c.courseNumber}
number={c.number}
/>
</div>
);
})
)}
</Carousel>
{recents.length == 0 ? (
<></>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove unnecessary fragments by using a logical AND:

{recents.length > 0 && (...)}

) : (
<Carousel title="Recently viewed" Icon={<Search />}>
{" "}
{recents
.filter(
(c) =>
!term || (c.year == term.year && c.semester == term.semester)
)
.map((c, i) => {
return (
<div key={i} className={styles.card}>
<CarouselClass
onSelect={onSelect}
subject={c.subject}
year={c.year}
semester={c.semester}
courseNumber={c.courseNumber}
number={c.number}
/>
</div>
);
})}
</Carousel>
)}
</Container>
</div>
);
Expand Down
11 changes: 9 additions & 2 deletions apps/frontend/src/app/Catalog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Class from "@/components/Class";
import ClassBrowser from "@/components/ClassBrowser";
import { useReadTerms } from "@/hooks/api";
import { useReadClass } from "@/hooks/api/classes/useReadClass";
import { Semester, TemporalPosition } from "@/lib/api";
import { ITerm, Semester, TemporalPosition } from "@/lib/api";

import styles from "./Catalog.module.scss";
import Dashboard from "./Dashboard";
Expand Down Expand Up @@ -45,6 +45,8 @@ export default function Catalog() {
return parseInt(providedYear) || null;
}, [providedYear]);

const [selectedTerm, changeTerm] = useState<ITerm | null>(null);

const term = useMemo(() => {
if (!terms) return null;

Expand All @@ -60,11 +62,12 @@ export default function Catalog() {
.find((term) => term.temporalPosition === TemporalPosition.Future);

return (
selectedTerm ??
terms?.find((term) => term.year === year && term.semester === semester) ??
currentTerm ??
nextTerm
);
}, [terms, year, semester]);
}, [terms, year, semester, selectedTerm]);

const subject = useMemo(
() => providedSubject?.toUpperCase(),
Expand Down Expand Up @@ -144,6 +147,10 @@ export default function Catalog() {
/>
) : (
<Dashboard
term={term}
termList={terms}
changeTerm={changeTerm}
onSelect={handleSelect}
expanded={expanded}
setExpanded={setExpanded}
setOpen={setOpen}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.root {
border: 1px solid var(--border-color);
border-radius: 8px;
flex-shrink: 0;
background-color: var(--foreground-color);
position: relative;
padding: 16px;
display: flex;
gap: 16px;
align-items: flex-start;
cursor: pointer;

&:hover .column .icon {
color: var(--heading-color);
}

.column {
display: flex;
flex-direction: column;
gap: 8px;
flex-shrink: 0;

.icon {
color: var(--paragraph-color);
transition: all 100ms ease-in-out;
}
}

.text {
flex-grow: 1;
font-size: 14px;
width: 80%;

.heading {
color: var(--heading-color);
margin-bottom: 8px;
line-height: 1;
font-weight: 660;
font-feature-settings:
"cv05" on,
"cv13" on,
"ss07" on,
"cv12" on,
"cv06" on;
}

.description {
color: var(--paragraph-color);
line-height: 1.5;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
width: 100%;
}

.row {
display: flex;
gap: 12px;
margin-top: 12px;
align-items: center;
float: bottom;
}
}
}

Loading