From 7307648cc085603e5ab75c6f8f43b0585d740929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=84=9D?= Date: Tue, 31 Jan 2023 23:12:31 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20:=20localstorage=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EA=B0=92=20=EB=B0=94=EB=A1=9C=20=EB=B9=BC=EB=83=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Page/Rolling.js | 49 ++++++++++++++++++++++++--------------------- src/Page/newMemo.js | 7 ++++++- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/Page/Rolling.js b/src/Page/Rolling.js index 38c5ca0..dbde82e 100644 --- a/src/Page/Rolling.js +++ b/src/Page/Rolling.js @@ -228,15 +228,30 @@ function Rolling() { const [isAdmin, setIsAdmin] = useState(false); // eslint-disable-next-line no-unused-vars const [loading, setLoading] = useState(false); + const [memoData, setMemoData] = useState({}); useEffect(() => { // 로컬에 ###메모지#### 내용이 들어있으면 if (localStorage.getItem('textcase') !== null) { setIsMemo(true); setIsActive(true); + const textcaseString = localStorage.getItem('textcase'); + const textcase = JSON.parse(textcaseString); + setMemoData({ + content: textcase.textcase.content, + nickname: textcase.textcase.nickname, + font: textcase.textcase.font, + password: textcase.textcase.password, + color: textcase.textcase.color, + font_color: textcase.textcase.fontColor, + }); + localStorage.removeItem('textcase'); } }, []); + useEffect(() => { + console.log(memoData); + }, [memoData]); const openPhotoModal = useCallback(() => setIsPhotoOpen(true), []); // 사진 모달창 열기 const closePhotoModal = useCallback(() => setIsPhotoOpen(false), []); // 사진 모달창 닫기 const openStickyModal = useCallback(() => setIsStickyOpen(true), []); // 스티커 모달창 열기 @@ -292,26 +307,17 @@ function Rolling() { return; } - const textcaseString = localStorage.getItem('textcase'); - const textcase = JSON.parse(textcaseString); - textcase.textcase.xcoor = coor.x; - textcase.textcase.ycoor = coor.y; + console.log(memoData); + try { - await axios.post(`${backBaseUrl}/api/v1/papers/${paperId}/memos`, { - content: textcase.textcase.content, - nickname: textcase.textcase.nickname, - font: textcase.textcase.font, - password: textcase.textcase.password, - color: textcase.textcase.color, - font_color: textcase.textcase.fontColor, - xcoor: textcase.textcase.xcoor, - ycoor: textcase.textcase.ycoor, - }); + await axios.post( + `${backBaseUrl}/api/v1/papers/${paperId}/memos`, + memoData, + ); console.log('successSave!!!!'); setIsMemo(false); // 메모기능 비활성화 setIsActive(false); // 수정기능 비활성화 - localStorage.removeItem('textcase'); // 로컬에 저장돼있던 메모지 내용 지움 } catch (e) { // 서버에서 받은 에러 메시지 출력 console.log(e); @@ -362,10 +368,6 @@ function Rolling() { setLoading(true); console.log('start Resizing'); - console.log(photo); - console.log(photo.image_id); - console.log(coor); - console.log(paperId); axios .post(`${backBaseUrl}/api/v1/papers/${paperId}/xyphotos`, { image_id: photo.image_id, @@ -433,12 +435,13 @@ function Rolling() { // 스티커?메모지?사진? 확인해주고 어떤 것이 새로 생겨서 움직일 것인지 정해주는 함수 function isItem() { return isMemo ? ( - + ) : isSticky ? ( + - ) : isSticky ? ( - ) : isPhoto ? ( { setOpacity(false); setCoor(position); + setMemoData(prevState => ({ + ...prevState, + xcoor: position.x, + ycoor: position.y, + })); }; return ( From f5bb609f8339bd96e2782ac906c440c23ef244b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=84=9D?= Date: Tue, 31 Jan 2023 23:14:37 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat=20:=20local=EB=A6=AC=EC=85=8B=ED=95=98?= =?UTF-8?q?=EA=B3=A0=20=EC=A0=80=EC=9E=A5=ED=95=98=EA=B2=8C=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Page/MemoText.js | 1 + src/Page/Rolling.js | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Page/MemoText.js b/src/Page/MemoText.js index f16267b..21ea09d 100644 --- a/src/Page/MemoText.js +++ b/src/Page/MemoText.js @@ -119,6 +119,7 @@ function MemoText({ if (textcase.nickname === '') { textcase.nickname = anonymous(); } + localStorage.removeItem('textcase'); localStorage.setItem('textcase', JSON.stringify({ textcase })); const paperId = localStorage.getItem('paperId'); navigate(`/rolling/${paperId}`); diff --git a/src/Page/Rolling.js b/src/Page/Rolling.js index dbde82e..5efe681 100644 --- a/src/Page/Rolling.js +++ b/src/Page/Rolling.js @@ -303,7 +303,6 @@ function Rolling() { setIsMemo(false); // 메모기능 비활성화 setIsActive(false); // 수정기능 비활성화 // setIsCancel(false); - localStorage.removeItem('textcase'); // 로컬에 저장돼있던 메모지 내용 지움 return; }