Skip to content

Commit

Permalink
스프린트미션10생성
Browse files Browse the repository at this point in the history
  • Loading branch information
hbs0133 committed Jul 22, 2024
1 parent 08b28dc commit b07eebb
Show file tree
Hide file tree
Showing 25 changed files with 637 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import React from "react";
import styles from "./BestPostCard.module.scss";
import Image from "next/image";
import medalIcon from "public/ic_medal.svg";
import heartIcon from "public/ic_heart.svg";

const BestPostCard = ({ item }) => {
interface PostItem {
content: string;
image?: string;
likeCount: number;
title: string;
createdAt: string;
writer: {
nickname: string;
};
}

const BestPostCard = ({ item }: { item: PostItem }) => {
const {
content,
image,
Expand All @@ -11,7 +24,7 @@ const BestPostCard = ({ item }) => {
writer: { nickname },
} = item;

const formatDate = (dateString) => {
const formatDate = (dateString: string) => {
const dateObj = new Date(dateString);
const year = dateObj.getFullYear();
const month = String(dateObj.getMonth() + 1).padStart(2, "0");
Expand All @@ -23,7 +36,7 @@ const BestPostCard = ({ item }) => {
<div className={styles["best-post-card-container"]}>
<div className={styles["best-post-card-badge"]}>
<Image
src="/ic_medal.svg"
src={medalIcon}
alt="베스트상품에 붙는 메달모양 뱃지"
width={16}
height={16}
Expand All @@ -45,7 +58,7 @@ const BestPostCard = ({ item }) => {
<span className={styles["best-post-card-info-name"]}>{nickname}</span>
<span className={styles["best-post-card-info-likes"]}>
<Image
src="/ic_heart.svg"
src={heartIcon}
alt="좋아요수를 나타내는 하트모양아이콘"
width={16}
height={16}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,31 @@ import styles from "./BestPostsSection.module.scss";
import BestPostCard from "../BestPostCard/BestPostCard";
import { getPost } from "../api";

// export const getStaticProps = async () => {
// const BestPostsData = await getPost({
// page: 1,
// pageSize: 3,
// orderBy: "like",
// });
// const bestPosts = BestPostsData.list;
const SCREEN_SIZES = {
LARGE: 1199,
MEDIUM: 744,
};

// return {
// props: {
// bestPosts,
// },
// };
// };
const PAGE_SIZES = {
LARGE: 3,
MEDIUM: 2,
SMALL: 1,
};

const BestPostsSection = () => {
const [bestPosts, setBestPosts] = useState([]);
const [windowWidth, setWindowWidth] = useState(0);
const [pageSize, setPageSize] = useState(3);

const getPageSize = () => {
if (windowWidth > 1199) {
setPageSize(3);
if (windowWidth > SCREEN_SIZES.LARGE) {
setPageSize(PAGE_SIZES.LARGE);
}
if (windowWidth < 1199 && windowWidth > 744) {
setPageSize(2);
if (windowWidth < SCREEN_SIZES.LARGE && windowWidth > SCREEN_SIZES.MEDIUM) {
setPageSize(PAGE_SIZES.MEDIUM);
}
if (windowWidth < 744) {
setPageSize(1);
if (windowWidth < SCREEN_SIZES.MEDIUM) {
setPageSize(PAGE_SIZES.SMALL);
}
};

Expand Down
42 changes: 42 additions & 0 deletions components/CommentForm/CommentForm.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.comment-form-container {
width: 1200px;
display: flex;
flex-direction: column;
gap: 9px;
label {
font-weight: 600;
font-size: 16px;
color: var(--gray900);
}
textarea {
height: 104px;
padding: 16px 24px;
background-color: var(--gray100);
border: none;
border-radius: 12px;
resize: none;
&::placeholder {
font-weight: 400;
font-size: 16px;
color: var(--gray400);
}
&:focus {
outline: none;
}
}
button {
width: 74px;
height: 42px;
border: none;
border-radius: 8px;
background-color: var(--blue);
color: var(--gray100);
font-weight: 600;
font-size: 16px;
margin-left: auto;
&:disabled {
background-color: var(--gray400);
cursor: not-allowed;
}
}
}
25 changes: 25 additions & 0 deletions components/CommentForm/CommentForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { useState } from "react";
import styles from "./CommentForm.module.scss";

const CommentForm = () => {
const [content, setContent] = useState("");

const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
setContent(e.target.value);
};
return (
<form className={styles["comment-form-container"]}>
<label htmlFor="comment">댓글달기</label>
<textarea
name="comment"
id="comment"
value={content}
onChange={handleChange}
placeholder="댓글을 입력해주세요"
/>
<button disabled={!content}>등록</button>
</form>
);
};

export default CommentForm;
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import React from "react";
import styles from "./PostCard.module.scss";
import Image from "next/image";
import heartIcon from "public/ic_heart.svg";
import Link from "next/link";

const PostCard = ({ item }) => {
interface PostItem {
id: number;
content: string;
image?: string;
likeCount: number;
title: string;
createdAt: string;
writer: {
nickname: string;
};
}
const PostCard = ({ item }: { item: PostItem }) => {
const {
id,
content,
image,
likeCount,
createdAt,
writer: { nickname },
} = item;

const formatDate = (dateString) => {
const formatDate = (dateString: string) => {
const dateObj = new Date(dateString);
const year = dateObj.getFullYear();
const month = String(dateObj.getMonth() + 1).padStart(2, "0");
Expand All @@ -20,7 +34,7 @@ const PostCard = ({ item }) => {
};

return (
<div className={styles["post-card-container"]}>
<Link href={`/boards/${id}`} className={styles["post-card-container"]}>
<div className={styles["best-post-card-content"]}>
<p>{content}</p>
{image ? (
Expand All @@ -30,12 +44,11 @@ const PostCard = ({ item }) => {
<div className={styles["best-post-card-info"]}>
<span className={styles["best-post-card-info-name"]}>{nickname}</span>
<span className={styles["best-post-card-info-date"]}>
{" "}
{formatDate(createdAt)}
</span>
<span className={styles["best-post-card-info-likes"]}>
<Image
src="/ic_heart.svg"
src={heartIcon}
alt="좋아요수를 나타내는 하트모양아이콘"
width={16}
height={16}
Expand All @@ -45,7 +58,7 @@ const PostCard = ({ item }) => {
</span>
</span>
</div>
</div>
</Link>
);
};

Expand Down
52 changes: 52 additions & 0 deletions components/PostDetailSection/PostDetailSection.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.post-detail-section-container {
width: 1200px;
margin-top: 102px;
display: flex;
flex-direction: column;
gap: 16px;
.post-detail-section-title {
font-weight: 700;
font-size: 20px;
}
.post-detail-section-info {
display: flex;
align-items: center;
padding-bottom: 16px;
border-bottom: 1px solid var(--gray200);
.post-detail-section-profile-image {
margin-right: 16px;
}
.post-detail-section-info-name {
font-weight: 500;
font-size: 14px;
color: var(--gray600);
margin-right: 8px;
}
.post-detail-section-info-date {
font-weight: 400;
font-size: 14px;
color: var(--gray400);
padding-right: 32px;
border-right: 1px solid var(--gray200);
}
.post-detail-section-info-likes {
margin-left: 32px;
display: flex;
align-items: center;
height: 40px;
border: 1px solid var(--gray200);
border-radius: 35px;
padding: 4px 12px;
span {
font-weight: 500;
font-size: 16px;
color: var(--gray500);
}
}
}
.post-detail-section-content {
margin-top: 8px;
font-weight: 400;
font-size: 18px;
}
}
68 changes: 68 additions & 0 deletions components/PostDetailSection/PostDetailSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React from "react";
import styles from "./PostDetailSection.module.scss";
import Image from "next/image";
import profileIcon from "public/ic_profile.svg";
import heartIcon from "public/ic_heart.svg";

interface PostItem {
content: string;
image?: string;
likeCount: number;
title: string;
createdAt: string;
writer: {
nickname: string;
};
}

const PostDetailSection = ({ item }: { item: PostItem }) => {
const {
content,
image,
likeCount,
createdAt,
title,
writer: { nickname },
} = item;

const formatDate = (dateString: string) => {
const dateObj = new Date(dateString);
const year = dateObj.getFullYear();
const month = String(dateObj.getMonth() + 1).padStart(2, "0");
const day = String(dateObj.getDate()).padStart(2, "0");
return `${year}.${month}.${day}`;
};

return (
<div className={styles["post-detail-section-container"]}>
<h1 className={styles["post-detail-section-title"]}>{title}</h1>
<div className={styles["post-detail-section-info"]}>
<Image
src={profileIcon}
alt="프로필을 나타내는 아이콘"
width={40}
height={40}
className={styles["post-detail-section-profile-image"]}
/>
<span className={styles["post-detail-section-info-name"]}>
{nickname}
</span>
<span className={styles["post-detail-section-info-date"]}>
{formatDate(createdAt)}
</span>
<span className={styles["post-detail-section-info-likes"]}>
<Image
src={heartIcon}
alt="좋아요를 나타내는 하트모양의 아이콘"
width={32}
height={32}
/>
<span>{likeCount}</span>
</span>
</div>
<p className={styles["post-detail-section-content"]}>{content}</p>
</div>
);
};

export default PostDetailSection;
Loading

0 comments on commit b07eebb

Please sign in to comment.