Skip to content

Commit 967b191

Browse files
authored
Merge pull request #100 from wafflestudio/seoyeon
Refactor code for Bookmark Login modal
2 parents 5696a7f + f13b3bc commit 967b191

3 files changed

Lines changed: 19 additions & 37 deletions

File tree

src/pages/CalendarView.tsx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { useUserData } from "@/contexts/UserDataContext";
2020
import BottomNav from "@/widgets/BottomNav";
2121
import { FilterSheet } from "@/widgets/FilterSheet/FilterSheet";
2222
import { useMonthEvents, useWeekEvents, useDayEvents } from "@/contexts/useCalendarEvents";
23-
import Modal from "@/widgets/Modal";
2423

2524
const CalendarView = () => {
2625
// EventContext
@@ -48,10 +47,7 @@ const CalendarView = () => {
4847
const [showSideMonth, setShowSideMonth] = useState<boolean>(false);
4948
const [clickedDate, setClickedDate] = useState<Date>(new Date());
5049

51-
// 로그인 모달
52-
const [isLoginModalOpen, setIsLoginModalOpen] = useState(false);
53-
54-
/** ---------------------- FETCH MONTH / WEEK / DAY data -------------------- */
50+
/** ---------------------- FETCH MONTH / WEEK / DAY data -------------------- */
5551

5652
const navigate = useNavigate();
5753

@@ -191,7 +187,7 @@ const CalendarView = () => {
191187
</div>
192188
{showSideMonth && (
193189
<div className={styles.sidePanel} ref={sidePanelRef}>
194-
<MonthSideView day={clickedDate} onClose={handleCloseSideMonth} onLoginPrompt={()=>setIsLoginModalOpen(true)}/>
190+
<MonthSideView day={clickedDate} onClose={handleCloseSideMonth} />
195191
</div>
196192
)}
197193

@@ -203,18 +199,6 @@ const CalendarView = () => {
203199
<DetailView eventId={clickedEventId} />
204200
</div>
205201
)}
206-
207-
{isLoginModalOpen && (
208-
<Modal
209-
content="로그인 이후 이용해주세요"
210-
leftText="로그인"
211-
rightText="닫기"
212-
onLeftClick={() => navigate("/")}
213-
onRightClick={() => setIsLoginModalOpen(false)}
214-
onClose={() => setIsLoginModalOpen(false)}
215-
/>
216-
)}
217-
218202
</div>
219203
<FilterSheet />
220204
<BottomNav />

src/pages/MainDay.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from "react";
1+
import { useEffect } from "react";
22
import { useNavigate } from "react-router-dom";
33
import styles from "@styles/CalendarView.module.css";
44
import MonthSideView from "@widgets/Month/MonthSideView/MonthSideView";
@@ -7,16 +7,13 @@ import BottomNav from "@/widgets/BottomNav";
77
import { useEvents } from "@/contexts/EventContext";
88
import { useDetail } from "@/contexts/DetailContext";
99
import { FilterSheet } from "@/widgets/FilterSheet/FilterSheet";
10-
import Modal from "@/widgets/Modal";
1110

1211
const MOBILE_MAX_WIDTH = 576;
1312

1413
const MainDay = () => {
1514
const navigate = useNavigate();
1615
const { dayDate } = useEvents();
1716
const { showDetail, clickedEventId } = useDetail();
18-
const [isLoginModalOpen, setIsLoginModalOpen] = useState(false);
19-
2017

2118
useEffect(() => {
2219
const checkWidth = () => {
@@ -36,7 +33,7 @@ const MainDay = () => {
3633
return (
3734
<div className={`${styles.container} ${styles.mainDay}`}>
3835
<div className={styles.calendarContainer}>
39-
<MonthSideView day={dayDate} onClose={handleClose} onLoginPrompt={()=>setIsLoginModalOpen(true)} />
36+
<MonthSideView day={dayDate} onClose={handleClose} />
4037
{showDetail && clickedEventId !== undefined && (
4138
<div className={`${styles.sidePanel} ${styles.detailPanel}`}>
4239
<DetailView eventId={clickedEventId} />
@@ -45,17 +42,6 @@ const MainDay = () => {
4542
</div>
4643
<FilterSheet />
4744
{!showDetail && <BottomNav />}
48-
{isLoginModalOpen && (
49-
<Modal
50-
content="로그인 이후 이용해주세요"
51-
leftText="로그인"
52-
rightText="닫기"
53-
onLeftClick={() => navigate("/")}
54-
onRightClick={() => setIsLoginModalOpen(false)}
55-
onClose={() => setIsLoginModalOpen(false)}
56-
/>
57-
)}
58-
5945
</div>
6046
);
6147
};

src/widgets/Month/MonthSideView/MonthSideView.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useMemo, useState } from "react";
2+
import { useNavigate } from "react-router-dom";
23
import { FaAngleLeft, FaAngleRight, FaAnglesRight } from "react-icons/fa6";
34
import styles from "@styles/MonthSideView.module.css";
45
import CardView from "./CardView";
@@ -12,16 +13,17 @@ import { useFilter } from "@/contexts/FilterContext";
1213
import { useUserData } from "@/contexts/UserDataContext";
1314
import { useDayEvents } from "@/contexts/useCalendarEvents";
1415
import { FilterButton } from "@/widgets/Toolbar";
16+
import Modal from "@/widgets/Modal";
1517

1618
const MonthSideView = ({
1719
day,
1820
onClose,
19-
onLoginPrompt,
2021
}: {
2122
day: Date;
2223
onClose: () => void;
23-
onLoginPrompt: () => void;
2424
}) => {
25+
const navigate = useNavigate();
26+
const [isLoginModalOpen, setIsLoginModalOpen] = useState(false);
2527
const { setShowDetail, setClickedEventId } = useDetail();
2628
const [date, setDate] = useState<Date>(day);
2729
const { globalCategory, globalOrg, globalStatus, setFilterSheetShowing } = useFilter();
@@ -76,6 +78,16 @@ const MonthSideView = ({
7678

7779
return (
7880
<div className={styles.mainWrapper}>
81+
{isLoginModalOpen && (
82+
<Modal
83+
content="로그인 이후 이용해주세요"
84+
leftText="로그인"
85+
rightText="닫기"
86+
onLeftClick={() => navigate("/")}
87+
onRightClick={() => setIsLoginModalOpen(false)}
88+
onClose={() => setIsLoginModalOpen(false)}
89+
/>
90+
)}
7991
<button type="button" className={styles.foldBtn} onClick={onClose}>
8092
<FaAnglesRight
8193
width={24}
@@ -112,7 +124,7 @@ const MonthSideView = ({
112124
onKeyDown={(e) => e.key === "Enter" && handleDetailClick(event.id)}
113125
className={styles.cardButton}
114126
>
115-
<CardView key={event.id} event={event} onLoginPrompt={onLoginPrompt} />
127+
<CardView key={event.id} event={event} onLoginPrompt={() => setIsLoginModalOpen(true)} />
116128
</div>
117129
))}
118130
</div>

0 commit comments

Comments
 (0)