Skip to content

Commit

Permalink
feat: boardId 저장값 수정, 수정 기능에 카테고리 상태 들어오도록 수정 #45
Browse files Browse the repository at this point in the history
  • Loading branch information
jizerozz committed Oct 26, 2024
1 parent 3877d2c commit e41a0c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
15 changes: 10 additions & 5 deletions src/pages/PostDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ const PostDetail = () => {
const [error, setError] = useState<string | null>(null)
const { sessionId } = useAuthStore()
const navigate = useNavigate()
const { userName } = useAuthStore()

const handlePostEdit = () => {
navigate(`/write?id=${postId}`, { state: { postData } })
}

console.log(postData)
useEffect(() => {
const fetchPostData = async () => {
try {
Expand Down Expand Up @@ -77,10 +78,14 @@ const PostDetail = () => {
<span>{formatDate(postData.createdAt)}</span>
<span>{postData.userNickname}</span>
</DateName>
<EditDelete>
<button onClick={handlePostEdit}>수정</button>
<button>삭제</button>
</EditDelete>
{userName === postData.userNickname ? (
<EditDelete>
<button onClick={handlePostEdit}>수정</button>
<button>삭제</button>
</EditDelete>
) : (
''
)}
</MetaData>
</div>
</TitleContainer>
Expand Down
17 changes: 8 additions & 9 deletions src/pages/WritePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,22 @@ const WritePage = () => {
}
}

useEffect(() => {
if (board) {
setBoardId(Number(board))
}
}, [board])

useEffect(() => {
if (id && post) {
setIsEditing(true)

setTitle(post.title)
setContent(post.content)
setCategory(post.category)
setBoard(post.subCategory)
setCategory(post.categoryId)
setBoard(post.boardId)
}
}, [id, post])

useEffect(() => {
if (category) {
setBoardId(Number(category))
}
}, [category])

return (
<Container>
<Toast />
Expand Down

0 comments on commit e41a0c1

Please sign in to comment.