-
Notifications
You must be signed in to change notification settings - Fork 35
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 #291 from MELATONIN99/Next-염성진-sprint10
[염성진] Sprint10
- Loading branch information
Showing
18 changed files
with
1,027 additions
and
41 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,91 @@ | ||
.main { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: left; | ||
margin-bottom: 32px; | ||
} | ||
.ProductInfoContainer { | ||
margin-bottom: 16px; | ||
border-bottom: 1px solid var(--gray200); | ||
} | ||
.titleContainer { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
} | ||
.title { | ||
width: 100%; | ||
font-size: 20px; | ||
font-weight: 700; | ||
color: var(--gray800); | ||
word-break: break-all; | ||
overflow-wrap: break-word; | ||
} | ||
.info { | ||
display: flex; | ||
align-items: center; | ||
margin: 16px 0px; | ||
} | ||
.writerNickName { | ||
font-size: 14px; | ||
font-weight: 500; | ||
color: var(--gray600); | ||
margin: 0 2px 0 16px; | ||
} | ||
.createdAt { | ||
height: 100%; | ||
font-size: 14px; | ||
font-weight: 400; | ||
color: var(--gray400); | ||
margin-right: 16px; | ||
} | ||
.favoriteContainer { | ||
border-left: 1px solid var(--gray200); | ||
} | ||
.favoriteBox { | ||
display: flex; | ||
align-items: center; | ||
gap: 10px; | ||
padding: 4px 12px; | ||
border-radius: 35px; | ||
border: 1px solid var(--gray200); | ||
margin-left: 16px; | ||
} | ||
.content { | ||
width: 100%; | ||
font-size: 16px; | ||
font-weight: 400; | ||
color: var(--gray800); | ||
word-break: break-all; | ||
overflow-wrap: break-word; | ||
} | ||
@media screen and (max-width: 1199px) and (min-width: 768px) { | ||
.main { | ||
margin-bottom: 40px; | ||
} | ||
.createdAt { | ||
margin-right: 32px; | ||
} | ||
.favoriteBox { | ||
margin-left: 32px; | ||
} | ||
.writerNickName { | ||
margin-right: 16px; | ||
} | ||
} | ||
|
||
@media screen and (min-width: 1200px) { | ||
.main { | ||
margin-bottom: 32px; | ||
} | ||
.createdAt { | ||
margin-right: 32px; | ||
} | ||
.favoriteBox { | ||
margin-left: 32px; | ||
} | ||
.writerNickName { | ||
margin-right: 8px; | ||
} | ||
} |
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,107 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useRouter } from "next/router"; | ||
import S from "@/components/DetailBoard.module.css"; | ||
import axios from "@/pages/api/axios"; | ||
import Image from "next/image"; | ||
|
||
interface ProductType { | ||
id: number; | ||
title: string; | ||
content: string; | ||
likeCount: number; | ||
createdAt: string; | ||
writer: { | ||
id: number; | ||
nickname: string; | ||
}; | ||
} | ||
|
||
function Product() { | ||
const [product, setProduct] = useState<ProductType>(); | ||
const [loading, setLoading] = useState(true); | ||
const router = useRouter(); | ||
const id = Number(router.query["id"]); | ||
|
||
// 작성한 시간 변환 함수 | ||
function formatDate(dateString: string): string { | ||
const date = new Date(dateString); | ||
const options: Intl.DateTimeFormatOptions = { | ||
year: "numeric", | ||
month: "2-digit", | ||
day: "2-digit", | ||
}; | ||
const formattedDate = date | ||
.toLocaleDateString("ko-KR", options) | ||
.replace(/\s+/g, "") | ||
.replace(/\//g, "."); | ||
|
||
return formattedDate.endsWith(".") ? formattedDate.slice(0, -1) : formattedDate; | ||
} | ||
|
||
// 게시판 데이터 가져오기 | ||
async function getProduct(id: number) { | ||
try { | ||
const res = await axios.get(`/articles/${id}`); | ||
const nextProduct = res.data; | ||
setProduct(nextProduct); | ||
} catch (error) { | ||
console.error(`유효하지 않은 주소입니다.`); | ||
router.replace(`/board`); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
getProduct(id); | ||
setLoading(false); | ||
}, [id]); | ||
|
||
if (loading) { | ||
return <div>Loading...</div>; | ||
} | ||
if (!product) { | ||
return <div>No data</div>; | ||
} | ||
|
||
const { title, content, likeCount, createdAt, writer } = product; | ||
return ( | ||
<main className={S.main}> | ||
<div className={S.ProductInfoContainer}> | ||
<div className={S.titleContainer}> | ||
<h2 className={S.title}>{title}</h2> | ||
<Image | ||
src="/images/icon/btn_icon/ic_kebab_menu.png" | ||
alt="게시글 수정 아이콘" | ||
width={24} | ||
height={24} | ||
/> | ||
</div> | ||
<div> | ||
<div className={S.info}> | ||
<Image | ||
src="/images/icon/ic_null_user_profile_image.png" | ||
alt="사용자 프로필 이미지" | ||
width={40} | ||
height={40} | ||
/> | ||
<div className={S.writerNickName}>{writer.nickname}</div> | ||
<div className={S.createdAt}>{formatDate(createdAt)}</div> | ||
<div className={S.favoriteContainer}> | ||
<div className={S.favoriteBox}> | ||
<Image | ||
src="/images/icon/btn_icon/ic_favorite.png" | ||
alt="좋아요 하트 아이콘" | ||
width={24} | ||
height={24} | ||
/> | ||
{likeCount} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div className={S.content}>{content}</div> | ||
</main> | ||
); | ||
} | ||
|
||
export default Product; |
Oops, something went wrong.