-
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.
Merge pull request #339 from MovieReviewComment/feature/issue-162/ref…
…actor-card [#162] Refactor ReviewCard
- Loading branch information
Showing
7 changed files
with
120 additions
and
25 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,29 @@ | ||
import { getValidChildrenOfType } from '@/lib/utils/common/get-valid-children-of-type'; | ||
|
||
function Card({ children }: { children: React.ReactNode }) { | ||
const header = getValidChildrenOfType(children, CardHeader); | ||
const body = getValidChildrenOfType(children, CardBody); | ||
const footer = getValidChildrenOfType(children, CardFooter); | ||
|
||
return ( | ||
<div className="flex flex-col border-t p-6 [&:first-child]:border-none"> | ||
{header} | ||
{body} | ||
{footer} | ||
</div> | ||
); | ||
} | ||
|
||
function CardHeader({ children }: { children: React.ReactNode }) { | ||
return <>{children}</>; | ||
} | ||
|
||
function CardBody({ children }: { children: React.ReactNode }) { | ||
return <>{children}</>; | ||
} | ||
|
||
function CardFooter({ children }: { children: React.ReactNode }) { | ||
return <>{children}</>; | ||
} | ||
|
||
export default Object.assign(Card, { Header: CardHeader, Body: CardBody, Footer: CardFooter }); |
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,17 @@ | ||
import Link from 'next/link'; | ||
|
||
import Text from '@/components/common/server/text'; | ||
|
||
import { parseReviewContent } from '@/lib/utils/review/parse-review-content'; | ||
|
||
export function ReviewCardBody({ reviewId, content }: { reviewId: number; content: string }) { | ||
const { description } = parseReviewContent(content); | ||
|
||
return ( | ||
<> | ||
<Link href={`/review/${reviewId}`} className="mt-4"> | ||
<Text lineClamp={3}>{description}</Text> | ||
</Link> | ||
</> | ||
); | ||
} |
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,25 @@ | ||
import Link from 'next/link'; | ||
|
||
import Text from '@/components/common/server/text'; | ||
|
||
export function ReviewCardHeader({ | ||
reviewId, | ||
title, | ||
movieName, | ||
}: { | ||
reviewId: number; | ||
title: string; | ||
movieName: string; | ||
}) { | ||
return ( | ||
<> | ||
<Link href={`/review/${reviewId}`} className="w-fit"> | ||
<Text size="xl" weight="bold"> | ||
{title} | ||
</Text> | ||
</Link> | ||
|
||
<Text weight="medium">{movieName}</Text> | ||
</> | ||
); | ||
} |
2 changes: 1 addition & 1 deletion
2
...nts/review/client/review-card.stories.tsx → ...nts/review/server/review-card.stories.tsx
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,32 @@ | ||
import Card from '@/components/common/server/card'; | ||
import { ReviewCardBody } from '@/components/review/server/review-card-body'; | ||
import { ReviewCardFooter } from '@/components/review/server/review-card-footer'; | ||
import { ReviewCardHeader } from '@/components/review/server/review-card-header'; | ||
|
||
import type { Review } from '@/lib/definitions/review'; | ||
|
||
export function ReviewCard({ review }: { review: Review }) { | ||
const { content, createdAt, movieName, nickname, tag, updatedAt, title, replyCount, id } = review; | ||
|
||
return ( | ||
<Card> | ||
<Card.Header> | ||
<ReviewCardHeader reviewId={id} title={title} movieName={movieName} /> | ||
</Card.Header> | ||
|
||
<Card.Body> | ||
<ReviewCardBody reviewId={id} content={content} /> | ||
</Card.Body> | ||
|
||
<Card.Footer> | ||
<ReviewCardFooter | ||
replyCount={replyCount} | ||
createdAt={createdAt} | ||
updatedAt={updatedAt} | ||
nickname={nickname} | ||
tag={tag} | ||
/> | ||
</Card.Footer> | ||
</Card> | ||
); | ||
} |
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