-
Notifications
You must be signed in to change notification settings - Fork 18
[김태훈] sprint9 #121
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 11 commits into
codeit-bootcamp-frontend:Next-김태훈
from
SHAKALOHANA:Next-김태훈
Oct 29, 2024
The head ref may contain hidden characters: "Next-\uAE40\uD0DC\uD6C8"
Merged
[김태훈] sprint9 #121
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9e2025a
feat: boards.tsx
SHAKALOHANA 85646fa
feat: Header
SHAKALOHANA b72554a
feat: Dropdown 기능
SHAKALOHANA c16eb60
feat: SearchForm / 키워드 검색 기능
SHAKALOHANA 069f25c
feat: BestArticles / 반응형
SHAKALOHANA 2eb8b99
style: Dropdown / relative
SHAKALOHANA 308ccaa
style: font / heart(icon)
SHAKALOHANA 3d0f2fd
hotfix: BestArticles / 좋아요순
SHAKALOHANA deaacfd
hotfix: boards(index) 수정
SHAKALOHANA 222b76a
refactor: boards/index, BestArticles
SHAKALOHANA 3fa2439
refactor: boards/index, BestArticles
SHAKALOHANA 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
.ArticlesList { | ||
display: flex; | ||
flex-direction: column; | ||
margin: 0 auto; | ||
} | ||
|
||
.Article { | ||
display: flex; | ||
justify-content: space-between; | ||
margin: 16px; | ||
font-size: 20px; | ||
line-height: 32px; | ||
font-weight: 600; | ||
} | ||
|
||
.image { | ||
position: relative; | ||
z-index: 0; | ||
width: 72px; | ||
height: 72px; | ||
} | ||
|
||
.meta { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
gap: 16px; | ||
margin-left: 24px; | ||
} | ||
|
||
@media (min-width: 375px) and (max-width: 767px) { | ||
.ArticlesList { | ||
width: 343px; | ||
} | ||
} | ||
|
||
@media (min-width: 768px) { | ||
.ArticlesList { | ||
width: 696px; | ||
} | ||
} | ||
|
||
@media (min-width: 1280px) { | ||
.ArticlesList { | ||
width: 1200px; | ||
} | ||
} |
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,58 @@ | ||
import React from "react"; | ||
import Link from "next/link"; | ||
import styles from "./ArticlesList.module.css"; | ||
import Image from "next/image"; | ||
import profile from "./assets/images/ui/ic_profile.svg"; | ||
import heart from "./assets/images/icons/ic_heart.svg"; | ||
|
||
interface Article { | ||
updatedAt: string; | ||
createdAt: string; | ||
likeCount: number; | ||
writer: { | ||
nickname: string; | ||
id: number; | ||
}; | ||
id: number; | ||
title: string; | ||
image: string; | ||
content: string; | ||
} | ||
|
||
interface ArticlesListProps { | ||
articles: Article[]; | ||
} | ||
|
||
const ArticlesList: React.FC<ArticlesListProps> = ({ articles }) => { | ||
if (!articles || articles.length === 0) { | ||
return <div>No articles available</div>; | ||
} | ||
|
||
return ( | ||
<div className={styles.ArticlesList}> | ||
{articles.map((article) => ( | ||
<div key={article.id}> | ||
<div className={styles.Article}> | ||
<h3>{article.title}</h3> | ||
<div className={styles.image}> | ||
<Image fill src={article.image} alt={article.image} /> | ||
</div> | ||
</div> | ||
<div className={styles.meta}> | ||
<div> | ||
<Image width={24} height={24} src={profile} alt={profile} /> | ||
<span> {article.writer.nickname} </span> | ||
<span> {new Date(article.updatedAt).toLocaleDateString()} </span> | ||
</div> | ||
<div> | ||
<Image width={24} height={24} src={heart} alt={heart} /> | ||
<span> {article.likeCount}+</span> | ||
</div> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ArticlesList; |
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,62 @@ | ||
@media (min-width: 375px) and (max-width: 767px) { | ||
.BestArticles { | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
} | ||
} | ||
|
||
@media (min-width: 768px) { | ||
.BestArticles { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
} | ||
.title { | ||
margin: 16px 24px; | ||
} | ||
} | ||
|
||
@media (min-width: 1280px) { | ||
.BestArticles { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr 1fr; | ||
} | ||
} | ||
|
||
.title { | ||
display: flex; | ||
justify-content: space-between; | ||
margin: 16px 24px; | ||
font-size: 20px; | ||
line-height: 32px; | ||
font-weight: 600; | ||
} | ||
|
||
.image { | ||
position: relative; | ||
z-index: 0; | ||
width: 72px; | ||
height: 72px; | ||
} | ||
|
||
.meta { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
gap: 16px; | ||
margin-left: 24px; | ||
margin-right: 24px; | ||
} | ||
|
||
.metaItem { | ||
display: flex; | ||
align-items: center; | ||
gap: 4px; | ||
} | ||
|
||
.metaItem span { | ||
margin-left: 4px; | ||
} | ||
|
||
.bestbadge { | ||
margin-left: 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,96 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import styles from "./BestArticles.module.css"; | ||
import Image from "next/image"; | ||
import bestbadge from "./assets/images/ui/best_badge.svg"; | ||
import axios from "@/lib/axios"; | ||
import heart from "./assets/images/icons/ic_heart.svg"; | ||
|
||
interface Article { | ||
updatedAt: string; | ||
createdAt: string; | ||
likeCount: number; | ||
writer: { | ||
nickname: string; | ||
id: number; | ||
}; | ||
id: number; | ||
title: string; | ||
image: string; | ||
content: string; | ||
} | ||
|
||
const BestArticles: React.FC = () => { | ||
const [articles, setArticles] = useState<Article[]>([]); | ||
const [pageSize, setPageSize] = useState<number>(1); | ||
|
||
useEffect(() => { | ||
const updatePageSize = () => { | ||
const width = window.innerWidth; | ||
if (width >= 375 && width <= 767) { | ||
setPageSize(1); | ||
} else if (width >= 768 && width < 1280) { | ||
setPageSize(2); | ||
} else if (width >= 1280) { | ||
setPageSize(3); | ||
} | ||
}; | ||
|
||
updatePageSize(); | ||
window.addEventListener("resize", updatePageSize); | ||
|
||
return () => { | ||
window.removeEventListener("resize", updatePageSize); | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
const getBestArticles = async () => { | ||
try { | ||
const response = await axios.get(`articles?orderBy=like`); | ||
setArticles(response.data.list); | ||
} catch (error) { | ||
console.error("Error fetching best articles:", error); | ||
} | ||
}; | ||
|
||
getBestArticles(); | ||
}, [pageSize]); | ||
|
||
const bestArticles = Array.isArray(articles) | ||
? [...articles].sort((a, b) => b.likeCount - a.likeCount).slice(0, pageSize) | ||
: []; | ||
|
||
return ( | ||
<div className={styles.BestArticles}> | ||
{bestArticles.map((article) => ( | ||
<div key={article.id}> | ||
<Image | ||
className={styles.bestbadge} | ||
width={102} | ||
height={30} | ||
src={bestbadge} | ||
alt={bestbadge} | ||
/> | ||
<div className={styles.title}> | ||
<h3>{article.title}</h3> | ||
<div className={styles.image}> | ||
<Image fill src={article.image} alt={article.image} /> | ||
</div> | ||
</div> | ||
<div className={styles.meta}> | ||
<div className={styles.metaItem}> | ||
<span> {article.writer.nickname} </span> | ||
<Image width={16} height={16} src={heart} alt={heart} /> | ||
<span> {article.likeCount}+ </span> | ||
</div> | ||
<div className={styles.metaItem}> | ||
<span> {new Date(article.createdAt).toLocaleDateString()} </span> | ||
</div> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default BestArticles; |
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,23 @@ | ||
.button { | ||
background-color: var(--blue); | ||
color: #fff; | ||
padding: 11.5px 23px; | ||
border-radius: 8px; | ||
font-size: 16px; | ||
width: 88px; | ||
height: 42px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
font-weight: bold; | ||
cursor: pointer; | ||
margin: 16px; | ||
} | ||
|
||
.button:hover { | ||
background-color: var(--blue-hover); | ||
} | ||
|
||
.button:focus { | ||
background-color: var(--blue-focus); | ||
} |
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,13 @@ | ||
import React from "react"; | ||
import styles from "./CreateArticleButton.module.css"; | ||
import Link from "next/link"; | ||
|
||
const CreateArticleButton = () => { | ||
return ( | ||
<Link href={"/"} className={styles.button}> | ||
글쓰기 | ||
</Link> | ||
); | ||
}; | ||
|
||
export default CreateArticleButton; |
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,36 @@ | ||
.dropdown { | ||
position: relative; | ||
display: inline-block; | ||
} | ||
|
||
.dropdownButton { | ||
padding: 10px; | ||
font-size: 16px; | ||
cursor: pointer; | ||
} | ||
|
||
.dropdownMenu { | ||
position: absolute; | ||
top: 100%; | ||
left: 0; | ||
z-index: 1000; | ||
display: block; | ||
min-width: 160px; | ||
padding: 5px 0; | ||
margin: 0; | ||
font-size: 14px; | ||
text-align: left; | ||
list-style: none; | ||
background-color: #fff; | ||
border: 1px solid #ccc; | ||
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175); | ||
} | ||
|
||
.dropdownItem { | ||
padding: 8px 12px; | ||
cursor: pointer; | ||
} | ||
|
||
.dropdownItem:hover { | ||
background-color: #f1f1f1; | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2:
위에서 orderBy로 좋아요수로 정렬해서 데이터를 받아오고 있으니 또 정렬하지 않으셔도 될 것 같아요~