-
Notifications
You must be signed in to change notification settings - Fork 18
[나지원] sprint9 #122
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
Merged
GANGYIKIM
merged 7 commits into
codeit-bootcamp-frontend:Next-나지원
from
najitwo:Next-나지원-sprint9
Oct 29, 2024
The head ref may contain hidden characters: "Next-\uB098\uC9C0\uC6D0-sprint9"
Merged
[나지원] sprint9 #122
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
31028d8
chore: initialize project
najitwo 3de42d0
feat: add Header component
najitwo cd154cb
feat: implement BestBoards component
najitwo b5ba32b
feat: implement BoardList component
najitwo 23bb578
feat: implement search function
najitwo fec9eea
feat: implement prefetching for boards
najitwo c3604f6
chore: add next-env.d.ts for environment types
najitwo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -33,3 +33,6 @@ yarn-error.log* | |
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
# VS Code | ||
.vscode |
This file contains hidden or 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,19 @@ | ||
.container { | ||
width: 72px; | ||
height: 72px; | ||
padding: 12px; | ||
border-radius: 8px; | ||
border: 0.75px solid var(--gray200); | ||
background-color: #ffffff; | ||
flex: 0 0 auto; | ||
} | ||
|
||
.wrapper { | ||
width: 100%; | ||
height: 100%; | ||
position: relative; | ||
} | ||
|
||
.image { | ||
object-fit: contain; | ||
} |
This file contains hidden or 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,34 @@ | ||
import { useState } from "react"; | ||
import Image from "next/image"; | ||
import Container from "../layout/Container"; | ||
import styles from "./ArticleImage.module.css"; | ||
import defaultImg from "@/public/img_default.svg"; | ||
|
||
interface ImageProps { | ||
src: string | null; | ||
alt: string; | ||
} | ||
|
||
const ArticleImage = ({ src, alt }: ImageProps) => { | ||
const [imageSrc, setImageSrc] = useState(src ?? defaultImg); | ||
|
||
const handleImageError = () => { | ||
setImageSrc(defaultImg); | ||
}; | ||
|
||
return ( | ||
<Container className={styles.container}> | ||
<div className={styles.wrapper}> | ||
<Image | ||
fill | ||
src={imageSrc} | ||
alt={alt} | ||
className={styles.image} | ||
onError={handleImageError} | ||
/> | ||
</div> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default ArticleImage; |
This file contains hidden or 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,50 @@ | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
flex: 1; | ||
background-color: var(--gray50); | ||
padding: 0 24px 16px; | ||
} | ||
|
||
.content { | ||
display: flex; | ||
justify-content: space-between; | ||
gap: 40px; | ||
font-size: 1.125rem; | ||
font-weight: 600; | ||
line-height: 1.625rem; | ||
color: var(--gray800); | ||
margin-top: 16px; | ||
margin-bottom: 8px; | ||
} | ||
|
||
.info { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
font-size: 0.875rem; | ||
font-weight: 400; | ||
line-height: 1.5rem; | ||
} | ||
|
||
.user { | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
} | ||
|
||
.nickname { | ||
color: var(--gray600); | ||
} | ||
|
||
.date { | ||
color: var(--gray400); | ||
} | ||
|
||
@media screen and (min-width: 1200px) { | ||
.content { | ||
font-size: 1.25rem; | ||
line-height: 2rem; | ||
margin-bottom: 18px; | ||
} | ||
} |
This file contains hidden or 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,28 @@ | ||
import Badge from "../ui/Badge"; | ||
import Container from "../layout/Container"; | ||
import ArticleImage from "./ArticleImage"; | ||
import { ArticleProps } from "@/types/articleTypes"; | ||
import styles from "./BestBoard.module.css"; | ||
import LikeCount from "../ui/LikeCount"; | ||
import { formatDate } from "@/lib/formatDate"; | ||
|
||
const BestBoard = ({ article }: { article: ArticleProps }) => { | ||
return ( | ||
<Container className={styles.container}> | ||
<Badge /> | ||
<div className={styles.content}> | ||
{article.title} | ||
<ArticleImage src={article.image} alt={`${article.id} 이미지`} /> | ||
</div> | ||
<div className={styles.info}> | ||
<div className={styles.user}> | ||
<div className={styles.nickname}>{article.writer.nickname}</div> | ||
<LikeCount likeCount={article.likeCount} /> | ||
</div> | ||
<div className={styles.date}>{formatDate(article.createdAt)}</div> | ||
</div> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default BestBoard; |
This file contains hidden or 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,34 @@ | ||
.wrapper { | ||
padding-bottom: 24px; | ||
} | ||
|
||
.wrapper h2 { | ||
font-size: 1.125rem; | ||
font-weight: 700; | ||
line-height: 1.625rem; | ||
color: var(--gray900); | ||
margin-bottom: 16px; | ||
} | ||
|
||
.container { | ||
display: flex; | ||
gap: 16px; | ||
} | ||
|
||
@media screen and (min-width: 768px) { | ||
.wrapper h2 { | ||
font-size: 1.25rem; | ||
line-height: 1.5rem; | ||
margin-bottom: 24px; | ||
} | ||
} | ||
|
||
@media screen and (min-width: 1200px) { | ||
.wrapper { | ||
padding-bottom: 40px; | ||
} | ||
|
||
.container { | ||
gap: 24px; | ||
} | ||
} |
This file contains hidden or 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,51 @@ | ||
import { useCallback, useEffect, useState } from "react"; | ||
import BestBoard from "./BestBoard"; | ||
import Container from "../layout/Container"; | ||
import useResize from "@/hooks/useResize"; | ||
import { fetchData } from "@/lib/fetchData"; | ||
import { ArticleProps } from "@/types/articleTypes"; | ||
import styles from "./BestBoards.module.css"; | ||
|
||
const getPageSize = (width: number) => { | ||
if (width < 768) return 1; | ||
if (width < 1200) return 2; | ||
|
||
return 3; | ||
}; | ||
|
||
const BestBoards = () => { | ||
const [articles, setArticles] = useState([]); | ||
const [pageSize, setPageSize] = useState<number>(); | ||
najitwo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const viewportWidth = useResize(); | ||
const BASE_URL = "https://panda-market-api.vercel.app/articles"; | ||
|
||
const handleLoad = useCallback(async (size: number) => { | ||
const { list } = await fetchData(BASE_URL, { | ||
query: { pageSize: size, orderBy: "like" }, | ||
}); | ||
setArticles(list); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (!viewportWidth) return; | ||
|
||
const nextPageSize = getPageSize(viewportWidth); | ||
if (nextPageSize !== pageSize) { | ||
setPageSize(nextPageSize); | ||
handleLoad(nextPageSize); | ||
} | ||
}, [viewportWidth, handleLoad, pageSize]); | ||
|
||
return ( | ||
<section className={styles.wrapper}> | ||
<h2>베스트 게시글</h2> | ||
<Container className={styles.container}> | ||
{articles.map((article: ArticleProps) => ( | ||
<BestBoard key={article.id} article={article} /> | ||
))} | ||
</Container> | ||
</section> | ||
); | ||
}; | ||
|
||
export default BestBoards; |
This file contains hidden or 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,56 @@ | ||
.container { | ||
background-color: #fcfcfc; | ||
border-bottom: 1px solid var(--gray200); | ||
padding-bottom: 24px; | ||
} | ||
|
||
.content { | ||
display: flex; | ||
justify-content: space-between; | ||
font-size: 1.125rem; | ||
font-weight: 600; | ||
line-height: 1.625rem; | ||
color: var(--gray800); | ||
} | ||
|
||
.info { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
|
||
.authorInfo { | ||
font-size: 0.875rem; | ||
font-weight: 400; | ||
line-height: 1.5rem; | ||
} | ||
|
||
.authorInfo img { | ||
width: 24px; | ||
height: 24px; | ||
} | ||
|
||
.authorInfo span { | ||
color: var(--gray600); | ||
} | ||
|
||
.authorInfo time { | ||
color: var(--gray400); | ||
} | ||
|
||
.like img { | ||
width: 24px; | ||
height: 24px; | ||
} | ||
|
||
.like span { | ||
font-size: 1rem; | ||
line-height: 1.625rem; | ||
} | ||
|
||
@media screen and (min-width: 768px) { | ||
.content { | ||
font-size: 1.25rem; | ||
line-height: 2rem; | ||
margin-bottom: 18px; | ||
} | ||
} |
This file contains hidden or 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,27 @@ | ||
import { ArticleProps } from "@/types/articleTypes"; | ||
import Container from "../layout/Container"; | ||
import styles from "./Board.module.css"; | ||
import ArticleImage from "./ArticleImage"; | ||
import LikeCount from "../ui/LikeCount"; | ||
import AuthorInfo from "../ui/AuthorInfo"; | ||
|
||
const Board = ({ board }: { board: ArticleProps }) => { | ||
return ( | ||
<Container className={styles.container}> | ||
<div className={styles.content}> | ||
{board.title} | ||
<ArticleImage src={board.image} alt={`${board.id} 이미지`} /> | ||
</div> | ||
<div className={styles.info}> | ||
<AuthorInfo | ||
className={styles.authorInfo} | ||
nickname={board.writer.nickname} | ||
date={board.createdAt} | ||
/> | ||
<LikeCount className={styles.like} likeCount={board.likeCount} /> | ||
</div> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Board; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.