From 95c8698e0c433d329c71b2da264414fddd6e61c4 Mon Sep 17 00:00:00 2001 From: seo0o519 Date: Mon, 27 May 2024 16:33:54 +0900 Subject: [PATCH 1/2] Chore: add diary id recoil #116 --- src/components/common/DiaryPreviewContent.js | 12 ++++++++++-- src/components/common/TripCalendar.js | 1 + src/pages/CalendarPage.js | 4 +++- src/recoil/commonState.js | 11 +++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/components/common/DiaryPreviewContent.js b/src/components/common/DiaryPreviewContent.js index e96483a..4d0da19 100644 --- a/src/components/common/DiaryPreviewContent.js +++ b/src/components/common/DiaryPreviewContent.js @@ -6,8 +6,13 @@ import { COLOR } from "../../styles/color"; import leftBtn from "../../assets/icons/diary_left_btn.svg"; import rightBtn from "../../assets/icons/diary_right_btn.svg"; import moment from "moment"; +import { useRecoilState } from "recoil"; +import { tripIdState, diaryIdState } from "../../recoil/commonState"; const DiaryPreviewContent = ({ diaries }) => { + + const [tripId, setTripId] = useRecoilState(tripIdState); + const [diaryId, setDiaryId] = useRecoilState(diaryIdState); const navigate = useNavigate(); const [currentSlideIndex, setCurrentSlideIndex] = useState(0); const sliderRef = useRef(null); @@ -31,8 +36,10 @@ const DiaryPreviewContent = ({ diaries }) => { }; const goToDiary = () => { - const currentDiary = diaries[currentSlideIndex]; - navigate("/showdiary", { state: currentDiary.diaryID }); + setTripId(diaries[currentSlideIndex].travelID); + setDiaryId(diaries[currentSlideIndex].diaryID); + + navigate("/showdiary"); }; let content = null; // 조건부 렌더링을 위한 변수 @@ -83,6 +90,7 @@ DiaryPreviewContent.propTypes = { diaryTitle: PropTypes.string.isRequired, imagePath: PropTypes.string.isRequired, username: PropTypes.string.isRequired, + travelID: PropTypes.string.isRequired, }), ).isRequired, }; diff --git a/src/components/common/TripCalendar.js b/src/components/common/TripCalendar.js index 80a34d6..1949832 100644 --- a/src/components/common/TripCalendar.js +++ b/src/components/common/TripCalendar.js @@ -120,6 +120,7 @@ TripCalendar.propTypes = { diaryTitle: PropTypes.string.isRequired, imagePath: PropTypes.string.isRequired, username: PropTypes.string.isRequired, + travelID: PropTypes.string.isRequired, }), ).isRequired, }; diff --git a/src/pages/CalendarPage.js b/src/pages/CalendarPage.js index 04b2a82..b4457ee 100644 --- a/src/pages/CalendarPage.js +++ b/src/pages/CalendarPage.js @@ -15,13 +15,15 @@ const CalendarPage = () => { axios .get(`${SERVER_URL}/diary`, { withCredentials: true }) .then((res) => { + console.log(res); const transformedData = res.data.diarys_info.map((item) => { return { date: item.diary.date, username: item.diary.userName, diaryTitle: item.diary.title, imagePath: item.url, - diaryID: item.diary._id + diaryID: item.diary._id, + travelID: item.diary.travel, }; }); setDiaryInfo(transformedData); diff --git a/src/recoil/commonState.js b/src/recoil/commonState.js index 56bbd8d..920740d 100644 --- a/src/recoil/commonState.js +++ b/src/recoil/commonState.js @@ -9,3 +9,14 @@ export const tripNameState = atom({ key: "tripName", default: "", }); + +export const tripIdState = atom({ + key: "tripId", + default: "", +}); + +export const diaryIdState = atom({ + key: "diaryId", + default: "", +}); + From 7afab3952cc74023d13fe1e097ec06d3f3b27917 Mon Sep 17 00:00:00 2001 From: seo0o519 Date: Mon, 27 May 2024 18:28:16 +0900 Subject: [PATCH 2/2] Chore: add diary id recoil in invite friend page #116 --- src/pages/InviteFriendPage.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages/InviteFriendPage.js b/src/pages/InviteFriendPage.js index 11c8b4c..625b323 100644 --- a/src/pages/InviteFriendPage.js +++ b/src/pages/InviteFriendPage.js @@ -6,17 +6,18 @@ import FriendList from "../components/common/FriendList.js"; import copyIcon from "../assets/icons/copy.svg"; import xicon from "../assets/icons/x-icon.svg"; import BottomNav from "../layout/BottomNav"; -import { useNavigate, useLocation } from "react-router-dom"; +import { useNavigate } from "react-router-dom"; import Modal from "../components/common/Modal"; import SuccessCopyContent from "../components/common/SuccessCopyContent.js"; +import { tripIdState } from "../recoil/commonState"; +import { useRecoilValue } from "recoil"; const InviteFriendPage = () => { const SERVER_URL = process.env.REACT_APP_SERVER_URL; const navigate = useNavigate(); + // navigate 하면서 받은 travel id 값 - const { state } = useLocation(); - // const travelID = state; <----------------나중에 주석 풀고 다음 줄 지우기 - const travelID = "664c951554d29fb5ec75847b"; // 임시로 쓴 것 + const travelID = useRecoilValue(tripIdState); // travel의 정보 const [invitecode, setInvitecode] = useState(""); const [title, setTitle] = useState("");