-
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 #289 from ojm51/Next-오정민-sprint10
[오정민] Sprint10
- Loading branch information
Showing
38 changed files
with
2,089 additions
and
199 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["prettier-plugin-tailwindcss"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { Dispatch, SetStateAction, useState } from "react"; | ||
import axios from "@/lib/axios"; | ||
import { IComment } from "@/types/comment"; | ||
|
||
import TextInput from "./Inputs/TextInput"; | ||
import AddButton from "./Buttons/AddButton"; | ||
|
||
const INPUT_CONTENT = [ | ||
{ | ||
name: "content", | ||
label: "댓글달기", | ||
placeholder: "댓글을 입력해주세요", | ||
isTextArea: true, | ||
}, | ||
]; | ||
|
||
interface AddCommentProps { | ||
id: number; | ||
setCommentList: Dispatch<SetStateAction<IComment[]>>; | ||
} | ||
|
||
function AddComment({ id, setCommentList }: AddCommentProps) { | ||
const [inputValue, setInputValue] = useState({ content: "" }); | ||
const [isFormComplete, setIsFormComplete] = useState(false); | ||
|
||
const handleValueChange = (name: string, value: string) => { | ||
setInputValue((prevValues) => ({ | ||
...prevValues, | ||
[name]: value, | ||
})); | ||
setIsFormComplete(value.trim() !== ""); | ||
}; | ||
|
||
async function postComment() { | ||
const accessToken = ""; | ||
|
||
let newComment: IComment; | ||
try { | ||
const response = await axios.post( | ||
`/articles/${id}/comments`, | ||
inputValue, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}, | ||
); | ||
|
||
newComment = response.data ?? []; | ||
console.log("post succeed: ", newComment); | ||
setCommentList((prevCommentList) => [newComment, ...prevCommentList]); | ||
} catch (error) { | ||
console.error("댓글 등록 중 오류가 발생했습니다: ", error); | ||
} finally { | ||
setInputValue({ | ||
content: "", | ||
}); | ||
} | ||
} | ||
|
||
return ( | ||
<div> | ||
{INPUT_CONTENT.map((content, index) => { | ||
return ( | ||
<TextInput | ||
key={index} | ||
content={content} | ||
onChange={handleValueChange} | ||
/> | ||
); | ||
})} | ||
<div className="text-right"> | ||
<AddButton | ||
buttonText="등록" | ||
isFormComplete={isFormComplete} | ||
onClick={postComment} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default AddComment; | ||
|
||
// const [inputValue, setInputValue] = useState({ | ||
// content: "", | ||
// }); | ||
// const [isFormComplete, setIsFormComplete] = useState(false); | ||
|
||
// const handleValueChange = (name: string, value: string) => { | ||
// setInputValue((prevValues) => ({ | ||
// ...prevValues, | ||
// [name]: value, | ||
// })); | ||
// setIsFormComplete(value.trim() !== ""); | ||
// }; | ||
|
||
// async function postComment() { | ||
// const accessToken = | ||
// "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjUsInNjb3BlIjoiYWNjZXNzIiwiaWF0IjoxNzIzNzczNzEzLCJleHAiOjE3MjM3NzU1MTMsImlzcyI6InNwLXBhbmRhLW1hcmtldCJ9.heZocGCQOejK4JPnWgWzJ438vW1sE2RAsj5d6ZHIhbc"; | ||
|
||
// let newComment: IComment; | ||
// try { | ||
// const data = { | ||
// ...inputValue, | ||
// }; | ||
// const response = await axios.post(`/articles/${id}/comments`, data, { | ||
// headers: { | ||
// Authorization: `Bearer ${accessToken}`, | ||
// }, | ||
// }); | ||
// newComment = response.data ?? []; | ||
// setCommentList((prevCommentList) => [newComment, ...prevCommentList]); | ||
// } catch (error) { | ||
// console.error("댓글 등록 중 오류가 발생했습니다: ", error); | ||
// } | ||
// } |
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
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,25 @@ | ||
interface AddButtonProps { | ||
buttonText: string; | ||
isFormComplete?: boolean; | ||
onClick: () => void; | ||
} | ||
|
||
function AddButton({ | ||
buttonText, | ||
isFormComplete = false, | ||
onClick, | ||
}: AddButtonProps) { | ||
let buttonClassNames = `rounded-lg px-6 py-2 text-gray-100 ${isFormComplete ? "bg-brand-blue" : "bg-gray-400"}`; | ||
|
||
return ( | ||
<button | ||
className={buttonClassNames} | ||
disabled={!isFormComplete} | ||
onClick={onClick} | ||
> | ||
{buttonText} | ||
</button> | ||
); | ||
} | ||
|
||
export default AddButton; |
2 changes: 1 addition & 1 deletion
2
components/LinkButton.module.css → components/Buttons/LinkButton.module.css
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,50 @@ | ||
import { IComment } from "@/types/comment"; | ||
import getTimeElapsed from "@/lib/getTimeElapsed"; | ||
|
||
import Image from "next/image"; | ||
import defaultProfileImage from "@/assets/images/img_profile.png"; | ||
import kebabMenuIcon from "@/assets/images/ic_kebab.png"; | ||
|
||
interface CommentProps { | ||
comment: IComment; | ||
} | ||
|
||
function Comment({ comment }: CommentProps) { | ||
const { writer, content, updatedAt } = comment; | ||
const profileImage = writer.image || defaultProfileImage; | ||
|
||
const timeElapsed = getTimeElapsed(new Date(updatedAt)); | ||
|
||
return ( | ||
<div className="mb-6 border-b border-gray-200 bg-[#fcfcfc] pb-3"> | ||
<div className="mb-6 flex items-center justify-between"> | ||
<div>{content}</div> | ||
<button> | ||
<Image | ||
src={kebabMenuIcon} | ||
alt="케밥 메뉴 아아콘" | ||
width={24} | ||
height={24} | ||
/> | ||
</button> | ||
</div> | ||
<div className="flex items-center justify-start gap-2"> | ||
<Image | ||
className="writer image" | ||
src={profileImage} | ||
alt={`${writer.nickname}`} | ||
width={40} | ||
height={40} | ||
/> | ||
<div className="flex flex-col items-start justify-start"> | ||
<div className="text-xs font-normal text-gray-600"> | ||
{writer.nickname} | ||
</div> | ||
<div className="text-xs font-normal text-gray-400">{timeElapsed}</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default Comment; |
Oops, something went wrong.