Skip to content
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

[장용한] Sprint10 #297

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions api/types/articleApi.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import axios from "axios";

const API_URL = "https://panda-market-api.vercel.app";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NEXT 환경변수를 이용해서 관리해보시면 좋을 것 같아요 !
보안상의 이점이 있답니다.


export const postArticle = async (body: FormData) => {
try {
const response = await axios.post(API_URL, body);
return response.data;
} catch (error) {
console.error("Error posting board:", error);
throw error;
}
};
10 changes: 10 additions & 0 deletions api/types/comment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface Comment {
updateAt?: string;
createdAt: string;
likeCount: number;
image: string;
content: string;
title: string;
nickname: string;
id?: number;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했을때 id 필드는 옵셔널인가요? id는 거의 Required 일꺼같아서요 ~ !

}
18 changes: 4 additions & 14 deletions components/BestComment.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import { useEffect, useState } from "react";
import CommentCard from "./CommentCard";
import CommentCard from "./CommentCards";
import axios from "@/lib/axios";
import style from "@/components/BestComment.module.css";

interface Comment {
updateAt: string;
createdAt: string;
likeCount: number;
image: string;
content: string;
title: string;
nickname: string;
id: number;
}
import { Comment } from "@/api/types/comment";

interface CommentList {
list: Comment[];
Expand Down Expand Up @@ -56,11 +46,11 @@ const BestComment = () => {
return (
<div className={style.bestCommentContainer}>
<h1 className={style.sectionTitle}>베트스 게시글</h1>
<div className={style.bestCommentsCard}>
<ul className={style.bestCommentsCard}>
<li>
<CommentCard comments={comment} showBest={true} />
</li>
</div>
</ul>
</div>
);
};
Expand Down
52 changes: 0 additions & 52 deletions components/CommentCard.tsx

This file was deleted.

File renamed without changes.
45 changes: 45 additions & 0 deletions components/CommentCards.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import style from "@/components/CommentCards.module.css";
import Best from "@/image/icons/ic_best.svg";
import Heart from "@/image/icons/ic_heart.svg";
import { Comment } from "@/api/types/comment";
import Link from "next/link";

interface CommentProps {
comments: Comment[];
showBest?: boolean;
}

const CommentCards: React.FC<CommentProps> = ({
comments,
showBest = false,
}) => {
return (
<>
{comments.map((comments) => (
<Link href={`/boards/${comments.id}`}>
<div key={comments.id} className={style.cardcontainer}>
{showBest && <Best className={style.besticon} />}
<div className={style.sectioncontent}>
<p className={style.commentcontent}>{comments.content}</p>
<img
src={comments.image}
alt={comments.title}
className={style.commentimage}
/>
</div>
<div className={style.commentmetacontainer}>
<div className={style.commentmeta}>
<span>{comments.nickname}</span>
<Heart />
<span>{comments.likeCount}</span>
</div>
<p>{comments.createdAt}</p>
</div>
</div>
</Link>
))}
</>
);
};

export default CommentCards;
18 changes: 18 additions & 0 deletions components/FileInput.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.fileInputcontainer {
position: relative;
}

.button {
position: absolute;
background-color: transparent;
border: none;
left: 240px;
top: 8px;
cursor: pointer;
}

.inputImage {
width: 282px;
height: 282px;
border-radius: 12px;
}
63 changes: 63 additions & 0 deletions components/FileInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ChangeEvent, useEffect, useRef, useState } from "react";
import style from "./FileInput.module.css";
import Xbutton from "@/image/icons/ic_X.svg";

interface FileInputProps {
id: string;
name: string;
value: File | null;
onChange: (name: string, file: File | null) => void;
}

function FileInput({ name, value, onChange }: FileInputProps) {
const [preview, setPreview] = useState<string>();
const inputRef = useRef<HTMLInputElement>(null);

const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
const nextValue =
e.target.files && e.target.files.length > 0 ? e.target.files[0] : null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 부분을 ts-patterns와 같은 라이브러리를 사용해서 가독성을 높여보시는건 어떨까요?

onChange(name, nextValue);
};

const handleClearClick = () => {
const inputNode = inputRef.current;
if (!inputNode) return;

inputNode.value = "";
onChange(name, null);
};

useEffect(() => {
if (!value) return;

const nextPreview = URL.createObjectURL(value);
setPreview(nextPreview);

return () => {
setPreview(undefined);
URL.revokeObjectURL(nextPreview);
};
}, [value]);
Comment on lines +30 to +40
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL.createObjectURL을 이용해서 프리뷰 URL 생성 좋습니다 ~~

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그리고 언마운트시에 revoke도 좋아요 !


return (
<div className={style.fileInputcontainer}>
<input
id="imgFile"
type="file"
accept="image/png, image/jpeg"
onChange={handleChange}
ref={inputRef}
/>
{value && (
<>
<button onClick={handleClearClick} className={style.button}>
<Xbutton alt="취소버튼" />
</button>
<img src={preview} alt="" className={style.inputImage} />
</>
)}
</div>
);
}

export default FileInput;
2 changes: 1 addition & 1 deletion components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Header = () => {
</Link>
<nav>
<ul className={style.headusedmarket}>
<Link href="/Boards">
<Link href="/boards">
<li className={style.usedmarket}>자유게시판</li>
</Link>
<li className={style.usedmarket}>
Expand Down
12 changes: 12 additions & 0 deletions components/SearchForm.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
.commentcontiner {
margin-top: 40px;
}

.sronly {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip-path: inset(50%);
border: 0;
clip: rect(0 0 0 0);
}
Comment on lines +5 to +15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지난번에 말한거 적용하셨네용 ~~~ 👍

9 changes: 8 additions & 1 deletion components/SearchForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ChangeEvent, FormEvent, useEffect, useState } from "react";
import DropDown from "./DropDown";
import style from "@/components/SearchForm.module.css";
import { useRouter } from "next/router";
import Link from "next/link";

const SearchForm = ({ initalValue = "" }) => {
const router = useRouter();
Expand All @@ -24,9 +25,15 @@ const SearchForm = ({ initalValue = "" }) => {
<>
<div className={style.commentcontiner}>
<h1>게시글</h1>
<button>글쓰기</button>
<Link href={"/addboards"}>
<button>글쓰기</button>
</Link>
<form onSubmit={handleSubmit}>
<label htmlFor="search" className={style.sronly}>
게시글 검색
</label>
<input
id="search"
name="keyword"
value={value}
placeholder="검색할 상품을 입력해주세요"
Expand Down
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@tanstack/react-query": "^5.51.23",
"axios": "^1.7.3",
"next": "13.5.6",
"react": "^18",
Expand Down
43 changes: 0 additions & 43 deletions pages/Boards.tsx

This file was deleted.

Loading
Loading