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

[ Refactor/#459 ] postPage 수정하기 로직 에러 수정 #460

Closed
wants to merge 8 commits into from
Closed
5,000 changes: 0 additions & 5,000 deletions package-lock.json

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@emotion/styled": "^11.11.0",
"@tanstack/react-query": "^5.17.10",
"@tanstack/react-query-devtools": "^5.37.1",
"@tiptap/core": "^2.7.0",
"@tiptap/extension-blockquote": "^2.2.3",
"@tiptap/extension-color": "^2.2.3",
"@tiptap/extension-highlight": "^2.2.3",
Expand All @@ -34,10 +35,9 @@
"emotion-reset": "^3.0.1",
"history": "^5.3.0",
"lottie-react": "^2.4.0",
"quill-divider": "^0.2.0",
"postcss": "^8.4.21",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-quill": "^2.0.0",
"react-router-dom": "^6.26.1",
"react-slick": "^0.29.0",
"slick-carousel": "^1.8.1"
Expand Down
2 changes: 1 addition & 1 deletion public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* - Please do NOT serve this file on production.
*/

const PACKAGE_VERSION = '2.2.10'
const PACKAGE_VERSION = '2.4.11'
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
const activeClientIds = new Set()
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useBlockPageExit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useBlocker } from 'react-router-dom';
import { useEffect, useState } from 'react';

const useBlockPageExit = () => {
const useBlockPageExit = (handleExitAction?: () => void) => {
const [isPageExitModalOpen, setIsPageExitModalOpen] = useState(false);
const [ignoreBlocker, setIgnoreBlocker] = useState(false);

Expand Down Expand Up @@ -30,6 +30,7 @@ const useBlockPageExit = () => {
// 페이지 나가기 (이탈 모달 확인 누를 경우)
const handleExitPage = () => {
blocker?.proceed && blocker.proceed();
handleExitAction && handleExitAction();
};

return {
Expand Down
1 change: 0 additions & 1 deletion src/pages/groupFeed/components/GroupTodayWriteStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const GroupTodayWriteStyle = (props: GroupTodayWriteStylePropTypes) => {
const navigate = useNavigate();

const { todayInfo, isMember, groupId } = props;
console.log(todayInfo, 'in');

const handleNavigatePostPage = () => {
navigate(`/post/${groupId}/post`);
Expand Down
91 changes: 75 additions & 16 deletions src/pages/postPage/PostPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import styled from '@emotion/styled';
import { createBrowserHistory } from 'history';
import React, { useEffect, useReducer, useState } from 'react';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { replace, useLocation, useNavigate, useParams } from 'react-router-dom';

import DropDown from './components/DropDown';
import ImageUpload from './components/ImageUpload';
Expand Down Expand Up @@ -33,6 +33,7 @@ import Spacing from '../../components/commons/Spacing';
import useModal from '../../hooks/useModal';
import useBlockPageExit from '../../hooks/useBlockPageExit';
import { MODAL } from './constants/modalContent';
import Error from '../error/Error';

// editor content API 관련
interface editorStateType {
Expand Down Expand Up @@ -152,7 +153,7 @@ const editorFlowModalState: editorFlowModalType = {
const PostPage = () => {
// 페이지 이탈
const { isPageExitModalOpen, handleClosePageExitModal, handleExitPage, setIgnoreBlocker } =
useBlockPageExit();
useBlockPageExit(() => localStorage.removeItem('editPostState'));
const navigate = useNavigate();
const location = useLocation();
const history = createBrowserHistory();
Expand Down Expand Up @@ -277,17 +278,34 @@ const PostPage = () => {
useEffect(() => {
// 수정하기에서 넘어온 view일 경우 값 업데이트
if (type === 'edit') {
setEditPostId(location.state.postId);
setPreviewImgUrl(location.state.imageUrl);
setContentWithoutTag(location.state.title);
editorContentDispatch({
type: 'setEditValue',
topic: location.state.topic,
imageUrl: location.state.imageUrl,
title: location.state.title,
writer: location.state.writer === '작자미상' ? '작자미상' : '필명',
content: location.state.content,
});
const savedState = localStorage.getItem('editPostState');

if (savedState) {
const { postId, topic, writer, title, content, imageUrl } = JSON.parse(savedState);
setEditPostId(postId);
setPreviewImgUrl(imageUrl);
setContentWithoutTag(title);
editorContentDispatch({
type: 'setEditValue',
topic,
imageUrl,
title,
writer: writer === '작자미상' ? '작자미상' : '필명',
content: content,
Comment on lines +293 to +294
Copy link
Member

Choose a reason for hiding this comment

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

[p3] 이부분 writer가 "작자미상"이 아닐경우 "필명"이라는 값을 넣는 로직이 맞나요??
실제 필명이 들어가야하는건 아닌가해서 여쭤봅니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

이거 그
image

여기 보여주기 위한거여서 실제 필명이 아닌 '필명' 맞습니당!

});
} else {
setEditPostId(location.state.postId);
setPreviewImgUrl(location.state.imageUrl);
setContentWithoutTag(location.state.title);
editorContentDispatch({
type: 'setEditValue',
topic: location.state.topic,
imageUrl: location.state.imageUrl,
title: location.state.title,
writer: location.state.writer === '작자미상' ? '작자미상' : '필명',
content: location.state.content,
});
}
}
// 임시저장된 값으로 업데이트
if (type === 'post' && continueTempPost) {
Expand All @@ -305,6 +323,18 @@ const PostPage = () => {
}
}, [type, continueTempPost, tempTitle, tempContent]);

const setEditorContent = () => {
// 수정하기 -> 새로고침해서 값이 저장되어 있는 경우
const savedState = localStorage.getItem('editPostState');
if (savedState) {
const { content } = JSON.parse(savedState);
return content;
} else {
// 수정하기 -> 새로고침 안 한 상태일 경우
return location.state.content;
}
};

// 수정하기 제출하기
const { mutate: putEditContent } = usePutEditContent({
topicId: topics
Expand All @@ -328,6 +358,11 @@ const PostPage = () => {
editorFlowModalDispatch({ type: 'editContent' });
setIgnoreBlocker(true);
};
// 수정하기 모달 확인
const onClickEditSaveModalBtn = () => {
localStorage.removeItem('editPostState');
navigate(`/detail/${groupId}/${editPostId}`, { replace: true });
};
// 최초 글 임시 저장
const { mutate: postTempSaveContent } = usePostTempSaveContent({
groupId: groupId,
Expand Down Expand Up @@ -452,7 +487,7 @@ const PostPage = () => {
leftBtnText: '홈으로 가기',
leftBtnFn: () => navigate('/'),
rightBtnText: '글 확인하기',
rightBtnFn: () => navigate(`/detail/${groupId}/${editPostId}`),
rightBtnFn: onClickEditSaveModalBtn,
modalImgType: 'POST',
onClickBg: () => {},
};
Expand Down Expand Up @@ -510,11 +545,35 @@ const PostPage = () => {
// 새로고침 방지
const preventReload = (e: Event) => {
e.preventDefault();

const stateData = {
postId: location.state?.postId,
topic: location.state?.topic,
writer: location.state?.writer,
title: location.state?.title,
content: location.state?.content,
imageUrl: location.state?.imageUrl,
};

// 로컬스토리지에 기존 데이터가 있으면 가져오고, 없으면 새로운 값으로 설정
const savedState = localStorage.getItem('editPostState');
const existingState = savedState ? JSON.parse(savedState) : null;

if (type === 'edit') {
// 이전 저장된 값이 있으면 다시 저장
if (existingState) {
localStorage.setItem('editPostState', JSON.stringify(existingState));
} else {
// 새로 저장
localStorage.setItem('editPostState', JSON.stringify(stateData));
}
}
};

useEffect(() => {
(() => {
history.push(history.location);

window.addEventListener('beforeunload', preventReload);
})();

Expand Down Expand Up @@ -568,7 +627,7 @@ const PostPage = () => {
title={editorVal.title}
setTitle={setTitle}
tempContent={tempContent}
editContent={type === 'edit' ? location?.state?.content : ''}
editContent={type === 'edit' ? setEditorContent() : ''}
setEditorContent={setContent}
setContentWithoutTag={setContentWithoutTag}
/>
Expand Down Expand Up @@ -600,7 +659,7 @@ const PostPage = () => {

{/* 페이지 이탈 모달 */}
<DefaultModal
isModalOpen={isPageExitModalOpen}
isModalOpen={isPageExitModalOpen}
onClickBg={handleClosePageExitModal}
content={MODAL.PAGE_EXIT_WARN}
modalImg="CAUTION"
Expand Down
2 changes: 1 addition & 1 deletion src/pages/postPage/components/TipTap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface EditorPropTypes {
title: string | undefined;
setTitle: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
tempContent: string;
editContent: string;
editContent: string | undefined;
setEditorContent: (content: string) => void;
setContentWithoutTag: (content: string) => void;
}
Expand Down
Loading