Skip to content

Commit

Permalink
fix: 일기 작성, 일기 읽기 모달 아이콘 svg 형태로 수정
Browse files Browse the repository at this point in the history
기존 png로 불러오던 모양 데이터를 svg형태로 받아오도록 수정하였습니다.
  • Loading branch information
dbwhdtjr0457 committed Nov 29, 2023
1 parent 1c32fae commit 2224f68
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 134 deletions.
1 change: 1 addition & 0 deletions FE/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ module.exports = {
"prettier/prettier": ["error", { endOfLine: "auto" }],
"react/jsx-filename-extension": [1, { extensions: [".js", ".jsx"] }],
"react/prop-types": "off",
"import/no-extraneous-dependencies": ["off"],
},
};
8 changes: 4 additions & 4 deletions FE/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FE/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@react-three/drei": "^9.88.17",
"@react-three/drei": "^9.89.0",
"@react-three/fiber": "^8.15.10",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
Expand Down
88 changes: 11 additions & 77 deletions FE/src/components/DiaryModal/DiaryCreateModal.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable */

import React, { useEffect, useState } from "react";
import { useRecoilValue, useSetRecoilState } from "recoil";
import { useMutation, useQuery } from "react-query";
import { useMutation } from "react-query";
import styled from "styled-components";
import userAtom from "../../atoms/userAtom";
import diaryAtom from "../../atoms/diaryAtom";
import shapeAtom from "../../atoms/shapeAtom";
import ModalWrapper from "../../styles/Modal/ModalWrapper";
import DiaryModalHeader from "../../styles/Modal/DiaryModalHeader";
import deleteIcon from "../../assets/deleteIcon.svg";
Expand All @@ -26,7 +25,6 @@ function DiaryCreateModal(props) {
tags: [],
shapeUuid: "",
});
const [newShapeData, setNewShapeData] = useState(null);

useEffect(() => {
const handleBeforeUnload = (e) => {
Expand Down Expand Up @@ -62,15 +60,6 @@ function DiaryCreateModal(props) {
setDiaryData({ ...diaryData, tags: diaryData.tags.slice(0, -1) });
};

async function getShapeFn() {
return fetch("http://223.130.129.145:3005/shapes/default", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
}).then((res) => res.json());
}

async function createDiaryFn(data) {
return fetch("http://223.130.129.145:3005/diaries", {
method: "POST",
Expand All @@ -90,56 +79,6 @@ function DiaryCreateModal(props) {
});
}

const {
data: shapeData,
// isLoading: shapeIsLoading,
// isError: shapeIsError,
} = useQuery("shape", getShapeFn, {
onSuccess: (dataList) => {
setDiaryData((prev) => ({ ...prev, shapeUuid: dataList[0].uuid }));
const newDataList = dataList.map((data) => {
const getPromise = () =>
fetch(`http://223.130.129.145:3005/shapes/${data.uuid}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${userState.accessToken}`,
},
});

return getPromise()
.then((res) => {
const reader = res.body.getReader();
return new ReadableStream({
start(controller) {
function pump() {
return reader.read().then(({ done, value }) => {
if (done) {
controller.close();
return;
}
controller.enqueue(value);
return pump();
});
}
return pump();
},
});
})
.then((stream) => new Response(stream))
.then((res) => res.blob())
.then((blob) => URL.createObjectURL(blob))
.then((url) => {
data.shapeData = url;
});
});

Promise.all(newDataList).then(() => {
setNewShapeData(dataList);
});
},
});

const {
mutate: createDiary,
// isLoading: diaryIsLoading,
Expand Down Expand Up @@ -197,10 +136,7 @@ function DiaryCreateModal(props) {
}}
/>
</DiaryModalTagWrapper>
<DiaryModalShapeSelectBox
shapeData={newShapeData}
setDiaryData={setDiaryData}
/>
<DiaryModalShapeSelectBox setDiaryData={setDiaryData} />
<ModalSideButtonWrapper>
<ModalSideButton
onClick={() => {
Expand All @@ -226,7 +162,8 @@ function DiaryCreateModal(props) {
}

function DiaryModalShapeSelectBox(props) {
const { shapeData, setDiaryData } = props;
const { setDiaryData } = props;
const shapeState = useRecoilValue(shapeAtom);

return (
<ShapeSelectBoxWrapper>
Expand All @@ -235,18 +172,15 @@ function DiaryModalShapeSelectBox(props) {
<ShapeSelectText>직접 그리기</ShapeSelectText>
</ShapeSelectTextWrapper>
<ShapeSelectItemWrapper>
{shapeData?.map((shape) => (
{shapeState?.map((shape) => (
<ShapeSelectBoxItem
key={shape.uuid}
onClick={() =>
setDiaryData((prev) => ({ ...prev, shapeUuid: shape.uuid }))
}
onClick={() => {
console.log(shape.uuid);
setDiaryData((prev) => ({ ...prev, shapeUuid: shape.uuid }));
}}
>
<img
src={shape.shapeData}
alt='shape'
style={{ width: "100%", height: "100%" }}
/>
<div dangerouslySetInnerHTML={{ __html: shape.data }} />
</ShapeSelectBoxItem>
))}
</ShapeSelectItemWrapper>
Expand Down
60 changes: 15 additions & 45 deletions FE/src/components/DiaryModal/DiaryReadModal.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable */
/*eslint-disable*/

import React from "react";
import React, { useEffect } from "react";
import { useQuery } from "react-query";
import styled from "styled-components";
import { useRecoilState, useRecoilValue } from "recoil";
import diaryAtom from "../../atoms/diaryAtom";
import userAtom from "../../atoms/userAtom";
import shapeAtom from "../../atoms/shapeAtom";
import ModalWrapper from "../../styles/Modal/ModalWrapper";
import DiaryDeleteModal from "./DiaryDeleteModal";
import editIcon from "../../assets/edit.svg";
Expand Down Expand Up @@ -57,46 +58,19 @@ function DiaryReadModal(props) {
const { refetch } = props;
const [diaryState, setDiaryState] = useRecoilState(diaryAtom);
const userState = useRecoilValue(userAtom);
const shapeState = useRecoilValue(shapeAtom);
const [shapeData, setShapeData] = React.useState("");
const { data, isLoading, isError } = useQuery(
"diary",
() => getDiary(userState.accessToken, diaryState.diaryUuid),
{
onSuccess: (_data) => {
const getPromise = () =>
fetch(`http://223.130.129.145:3005/shapes/${_data.shapeUuid}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${userState.accessToken}`,
},
});

return getPromise()
.then((res) => {
const reader = res.body.getReader();
return new ReadableStream({
start(controller) {
function pump() {
return reader.read().then(({ done, value }) => {
if (done) {
controller.close();
return;
}
controller.enqueue(value);
return pump();
});
}
return pump();
},
});
})
.then((stream) => new Response(stream))
.then((res) => res.blob())
.then((blob) => URL.createObjectURL(blob))
.then((url) => {
setShapeData(url);
});
onSuccess: (data) => {
const shapeData = shapeState.find((item) => {
return item.uuid === data.shapeUuid;
});
if (shapeData) {
setShapeData(shapeData.data);
}
},
},
);
Expand Down Expand Up @@ -185,14 +159,10 @@ function DiaryReadModal(props) {
}}
/>
<DiaryModalIcon>
<img
src={shapeData}
alt='star'
style={{
width: "5rem",
height: "5rem",
}}
/>
<div
dangerouslySetInnerHTML={{ __html: shapeData }}
style={{ width: "100%", height: "100%" }}
></div>
</DiaryModalIcon>
</DiaryModalEmotionBar>
{diaryState.isDelete ? <DiaryDeleteModal refetch={refetch} /> : null}
Expand Down
7 changes: 0 additions & 7 deletions FE/src/pages/MainPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ function MainPage() {
}));
}}
/>
{shapeState.map((shape) => (
<div
key={shape.uuid}
dangerouslySetInnerHTML={{ __html: shape.data }}
/>
))}

<StarPage />
{diaryState.isCreate ? <DiaryCreateModal refetch={refetch} /> : null}
{diaryState.isRead ? <DiaryReadModal refetch={refetch} /> : null}
Expand Down

0 comments on commit 2224f68

Please sign in to comment.