Skip to content

Commit

Permalink
Merge pull request #103 from LikeLionHGU/eunju_feat/#98
Browse files Browse the repository at this point in the history
Eunju feat/#98
  • Loading branch information
ejPark43 authored Aug 4, 2024
2 parents 084fcf8 + 211b521 commit 22154cf
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 50 deletions.
18 changes: 2 additions & 16 deletions src/asset/Icon/Figma.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 3 additions & 17 deletions src/asset/Icon/HoverFigma.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions src/diaryDetailPage/components/DiaryDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ function DiaryDetail() {
<ContentArea>
<Contents>
{/* html 태그 적용된 일지 내용 보여주는 부분 */}
<div dangerouslySetInnerHTML={{ __html: diaryDetail.content }}></div>
<div
dangerouslySetInnerHTML={{ __html: diaryDetail.content }}
></div>
</Contents>
</ContentArea>
</CenterBox>

{deleteModal && <DeleteConfirmModal setDeleteModal={setDeleteModal} goalId={goalId} />}
{deleteModal && (
<DeleteConfirmModal setDeleteModal={setDeleteModal} goalId={goalId} />
)}
</BoxWrapper>
</Wrapper>
);
Expand Down
144 changes: 144 additions & 0 deletions src/diaryWritePage/components/DiaryEditModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
상위 컴포넌트에 들어갈 내용(DiaryWrite 참고):
const [editedModal, setEditedModal] = useState(false); //일지가 추가되었다는 걸 알려주는 모달
const [thumbnailModal, setThumbnailModal] = useState(false); // 썸네일 사진 추가하는 모달
{thumbnailModal && (
<ThumbnailModal
setThumbnailModal={setThumbnailModal}
setEditedModal={setEditedModal}
formData={formData}
goalId={goalId}
csrfToken={csrfToken}
/>
)}
{!thumbnailModal && postedModal && (
<DiaryPostModal setEditedModal={setEditedModal} goalId={goalId} />
)}
*/
import React from "react";
import styled from "styled-components";
import { useLocation, useNavigate } from "react-router-dom";

function DiaryEditModal({ setEditedModal }) {
const location = useLocation();
const navigate = useNavigate();
const { goalId, diaryDetail } = location.state;
const diaries = diaryDetail;

// location.state가 존재하고, goalId와 diaryDetail이 존재하는지 확인
if (
!location.state ||
!location.state.goalId ||
!location.state.diaryDetail
) {
console.error("Missing required state data");
return null; // 필수 데이터가 없으면 null 반환
}
console.log("Location state:", location.state);

const closeModal = () => {
setEditedModal(false); // !! 주석 풀기 !!
navigate(`/detail/`, { state: { diaries, goalId } });
};

return (
<div>
<ModalBackground>
<Overlay onClick={closeModal} />

<Wrapper>
<div className="title">일지가 수정되었어요</div>
<div className="save-content">
변경 사항이 성공적으로 저장되었습니다
<br />
계속해서 기록을 이어가보세요!
</div>
<CompleteBtn>
<button onClick={closeModal}>확인하기</button>
</CompleteBtn>
</Wrapper>
</ModalBackground>
</div>
);
}

export default DiaryEditModal;

const modalBase = `
width: 100vw;
height: 100vh;
top: 0;
left: 0;
right: 0;
bottom: 0;
position: fixed;
`;

const ModalBackground = styled.div`
${modalBase}
background: rgba(0, 0, 0, 0.2);
z-index: 4;
cursor: default;
`;
const Overlay = styled.div`
${modalBase}
cursor: default;
`;
const Wrapper = styled.div`
display: flex;
flex-direction: column;
/* justify-content: center; */
align-items: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #ffffff;
width: 350px; // 로딩모달 크기
min-height: 166px;
border-radius: 12px;
.title {
font-size: 18px;
font-weight: bold;
margin-top: 18px;
margin-bottom: 8px;
line-height: 150%;
}
.save-content {
width: 310px;
/* height: 100px; */
font-size: 14px;
text-align: center;
/* border: 2px solid red; */
line-height: 150%;
}
`;
const CompleteBtn = styled.div`
display: flex;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
margin-top: 16px;
/* border: 2px solid red; */
> button {
display: flex;
justify-content: center;
align-items: center;
outline: none;
border: none;
border-radius: 8px;
width: 201px;
height: 37px;
font-size: 14px;
font-weight: bold;
color: white;
background-color: #798bff;
cursor: pointer;
&:active {
background-color: #586eff;
}
}
`;
35 changes: 26 additions & 9 deletions src/diaryWritePage/components/ThumbnailModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import styled from "styled-components";
import CloseRoundedIcon from "@mui/icons-material/CloseRounded";
import AddRoundedIcon from "@mui/icons-material/AddRounded";
import createDiary from "../../apis/createDiary";
function ThumbnailModal({ setThumbnailModal, setPostedModal, formData, goalId, csrfToken }) {
function ThumbnailModal({
setThumbnailModal,
setEditedModal,
formData,
diaryDetail,
csrfToken,
}) {
// 이미지 설정//
const fileInputRef = useRef(null);
const [previewUrl, setPreviewUrl] = useState(null); // 미리보기창에 들어갈 이미지 url
Expand All @@ -17,10 +23,14 @@ function ThumbnailModal({ setThumbnailModal, setPostedModal, formData, goalId, c
fileInputRef.current.click();
};
const handleNextStep = async () => {
// 대표사진 선택하기 모달에서 "다음으로" 버튼 누르고 나면 사진선택 모달은 숨기고 그 이후 모달(일지 추가 완료 모달)을 보여줘야함.
// *** 이 함수 안에서 일지를 백엔드로 submit해야할듯 (내용 + 대표사진) *** //
// 일단 임시로 "다음으로"버튼 누르면 그 다음 모달로 넘어가는 것만 해둠.
// 아직 이미지는 보내는거 연결안했는데 백엔드 구현되면 수정해야함
//
setThumbnailModal(false);
setEditedModal(true);
// ^^^^^^ 나중에 이 부분 지우기

// *** 이 함수 안에서 수정된 일지를 백엔드로 submit할 필요 있음 (내용 + 대표사진) *** //
// TODO: (45번 라인 코드 부분)다이어리 수정하는 api 파일 생성하기 !!!!!! creatDiary말고 나중에 백엔드에서 일지 수정 api 생성하면 만들고 이 부분도 고치기.
// 아직 이미지는 보내는건 연결X 백엔드 구현되면 수정필요
try {
const { title, content } = formData;

Expand All @@ -32,9 +42,11 @@ function ThumbnailModal({ setThumbnailModal, setPostedModal, formData, goalId, c
if (fileInputRef.current.files[0]) {
formDataToSend.append("image", fileInputRef.current.files[0]);
}
await createDiary(formDataToSend, csrfToken, goalId);
// TODO: 다이어리 수정하는 api 파일 생성하기 !!!!!! creatDiary말고 나중에
// 백엔드에서 일지 수정 api 생성하면 만들고 이 부분도 고치기.
await createDiary(formDataToSend, csrfToken, diaryDetail);
setThumbnailModal(false);
setPostedModal(true);
setEditedModal(true);
} catch (error) {
console.error("일지 생성 실패", error);
}
Expand All @@ -60,7 +72,7 @@ function ThumbnailModal({ setThumbnailModal, setPostedModal, formData, goalId, c
<Wrapper>
<TopContainer>
<TopText>
대표사진 추가하기<span>(선택)</span>
대표사진 수정하기<span>(선택)</span>
</TopText>
<ExitButton onClick={closeThumbnailModal}>
<CloseRoundedIcon />
Expand All @@ -83,7 +95,12 @@ function ThumbnailModal({ setThumbnailModal, setPostedModal, formData, goalId, c
<div className="image-add-text">사진 추가하기</div>
</>
)}
<input type="file" style={{ display: "none" }} onChange={handleFileInputChange} ref={fileInputRef} />
<input
type="file"
style={{ display: "none" }}
onChange={handleFileInputChange}
ref={fileInputRef}
/>
</ImageAdd>
<Buttons>
<NextBtn>
Expand Down
Loading

0 comments on commit 22154cf

Please sign in to comment.