Skip to content

Commit

Permalink
fix: 수정하기, 새로고침 후 아무것도 안고치고 제출할 때 에러 방지
Browse files Browse the repository at this point in the history
  • Loading branch information
se0jinYoon committed Oct 22, 2024
1 parent 234b74d commit 91dcf23
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/pages/postPage/PostPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,14 @@ const PostPage = () => {
}, [type, continueTempPost, tempTitle, tempContent]);

const setEditorContent = () => {
// 수정하기 -> 새로고침해서 값이 저장되어 있는 경우
const savedState = localStorage.getItem('editPostState');
console.log(savedState);
if (savedState) {
const { content } = JSON.parse(savedState);
return content;
} else {
// 수정하기 -> 새로고침 안 한 상태일 경우
return location.state.content;
}
};
Expand All @@ -350,12 +353,16 @@ const PostPage = () => {
if (contentWithoutTag.trim().length !== 0 && editorVal.title?.trim().length !== 0) {
putEditContent();
}
localStorage.removeItem('editPostState');
handleShowModal();
setEditorModalType('editContent');
editorFlowModalDispatch({ type: 'editContent' });
setIgnoreBlocker(true);
};
// 수정하기 모달 확인
const onClickEditSaveModalBtn = () => {
localStorage.removeItem('editPostState');
navigate(`/detail/${groupId}/${editPostId}`);
};
// 최초 글 임시 저장
const { mutate: postTempSaveContent } = usePostTempSaveContent({
groupId: groupId,
Expand Down Expand Up @@ -480,7 +487,7 @@ const PostPage = () => {
leftBtnText: '홈으로 가기',
leftBtnFn: () => navigate('/'),
rightBtnText: '글 확인하기',
rightBtnFn: () => navigate(`/detail/${groupId}/${editPostId}`),
rightBtnFn: onClickEditSaveModalBtn,
modalImgType: 'POST',
onClickBg: () => {},
};
Expand Down

0 comments on commit 91dcf23

Please sign in to comment.