-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
239 additions
and
0 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
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,71 @@ | ||
import { type VariantProps, tv } from "tailwind-variants"; | ||
|
||
export type ReviewItemVariants = VariantProps<typeof reviewItemTheme>; | ||
|
||
export const reviewItemTheme = tv( | ||
{ | ||
slots: { | ||
wrapper: [ | ||
"flex", | ||
"flex-col", | ||
"p-2", | ||
"items-start", | ||
"w-[45rem]", | ||
"gap-[0.375rem]", | ||
], | ||
headingContainer: [ | ||
"flex", | ||
"self-stretch", | ||
"justify-between", | ||
"items-center", | ||
"rounded-none", | ||
"w-full", | ||
"gap-10", | ||
], | ||
schoolContainer: ["flex", "items-center", "gap-2"], | ||
schoolIcon: [], | ||
schoolCourseCode: [ | ||
"flex", | ||
"overflow-hidden", | ||
"text-sm", | ||
"text-ellipsis", | ||
"text-text-em-mid", | ||
], | ||
metadataContainer: ["flex", "gap-4", "items-center", "justify-end"], | ||
profileContainer: ["flex", "items-center", "gap-2"], | ||
profileName: [ | ||
"overflow-hidden", | ||
"text-sm", | ||
"text-ellipsis", | ||
"text-text-em-mid", | ||
], | ||
profileIcon: [], | ||
likeIcon: [], | ||
timedelta: [ | ||
"overflow-hidden", | ||
"text-sm", | ||
"text-ellipsis", | ||
"text-text-em-low", | ||
], | ||
body: [ | ||
"relative", | ||
"flex", | ||
"h-16", | ||
"w-full", | ||
"self-stretch", | ||
"overflow-hidden", | ||
"text-sm", | ||
"text-ellipsis", | ||
"text-text-em-high", | ||
], | ||
labels: [ | ||
"text-sm", | ||
"text-text-on-secondary", | ||
"flex", | ||
"gap-4", | ||
"items-start", | ||
], | ||
}, | ||
}, | ||
{ responsiveVariants: true }, | ||
); |
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,125 @@ | ||
import { Button } from "@/common/components/Button"; | ||
import { reviewItemTheme, type ReviewItemVariants } from "./ReviewItem.theme"; | ||
import { ThumbUpFilledIcon } from "@/common/components/CustomIcon"; | ||
import { LockCtaOverlay } from "@/common/components/LockCtaOverlay"; | ||
import { Tag } from "@/common/components/Tag"; | ||
import { getHumanReadableTimestampDelta } from "@/common/functions"; | ||
|
||
// TODO: to replace with prisma generated types | ||
export type Label = { | ||
name: string; | ||
typeof: "professor" | "course"; | ||
}; | ||
|
||
export type Review = { | ||
body: string; | ||
courseCode: string; | ||
username: string; | ||
likeCount: number; | ||
labels: Label[]; | ||
createdAt: number; | ||
}; | ||
|
||
export type ReviewItemProps = ReviewItemVariants & { | ||
review: Review; | ||
isLocked?: boolean; | ||
variant?: "home" | "subpage"; | ||
}; | ||
|
||
export const ReviewItem = ({ | ||
review, | ||
isLocked, | ||
variant = "home", | ||
}: ReviewItemProps) => { | ||
const { | ||
wrapper, | ||
headingContainer, | ||
schoolContainer, | ||
schoolIcon, | ||
schoolCourseCode, | ||
metadataContainer, | ||
profileContainer, | ||
profileName, | ||
profileIcon, | ||
likeIcon, | ||
timedelta, | ||
body, | ||
labels, | ||
} = reviewItemTheme({ variant }); | ||
|
||
const HeaderCourse = () => ( | ||
<div className={schoolContainer()}> | ||
<div className={schoolIcon()}> | ||
<div className="h-4 w-4 rounded-full bg-red-800"></div> | ||
</div> | ||
<div className={schoolCourseCode()}>{review.courseCode}</div> | ||
</div> | ||
); | ||
|
||
const HeaderReviewer = () => ( | ||
<div className={profileContainer()}> | ||
<div className={profileIcon()}> | ||
<div className="h-4 w-4 rounded-full bg-cyan-800"></div> | ||
</div> | ||
<div className={profileName()}>{review.username}</div> | ||
</div> | ||
); | ||
|
||
const ReviewContent = ({ isDetailed }: { isDetailed: boolean }) => { | ||
return ( | ||
<div className="flex flex-col gap-1"> | ||
{isDetailed && ( | ||
<div className={labels()}> | ||
{review.labels | ||
.filter((label) => label.typeof === "professor") | ||
.map((label) => ( | ||
<span key={label.name}>{label.name}</span> | ||
))} | ||
</div> | ||
)} | ||
{isDetailed && ( | ||
<div className={labels()}> | ||
{review.labels | ||
.filter((label) => label.typeof === "course") | ||
.map((label) => ( | ||
<span key={label.name}>{label.name}</span> | ||
))} | ||
</div> | ||
)} | ||
<div className={body()}>{review.body}</div> | ||
{isDetailed && ( | ||
<Button variant="link" as="button"> | ||
Show more | ||
</Button> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className={wrapper()}> | ||
<div className={headingContainer()}> | ||
{variant === "home" ? <HeaderCourse /> : <HeaderReviewer />} | ||
<div className={metadataContainer()}> | ||
{variant === "home" ? <HeaderReviewer /> : <HeaderCourse />} | ||
<Tag | ||
variant="secondary" | ||
contentRight={<ThumbUpFilledIcon className={likeIcon()} />} | ||
> | ||
{review.likeCount} | ||
</Tag> | ||
<div className={timedelta()}> | ||
{getHumanReadableTimestampDelta(review.createdAt)} | ||
</div> | ||
</div> | ||
</div> | ||
{isLocked ? ( | ||
<div className={body()}> | ||
<LockCtaOverlay size="sm" ctaType="review" variant="border" /> | ||
</div> | ||
) : ( | ||
<ReviewContent isDetailed={variant === "subpage"} /> | ||
)} | ||
</div> | ||
); | ||
}; |
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,2 @@ | ||
export * from "./ReviewItem"; | ||
export * from "./ReviewItem.theme"; |