Skip to content

Commit 5edd673

Browse files
authored
Merge pull request #68 from pythonkr/fix/session-timetable-preserve-state-on-back
fix: 세션 시간표가 페이지 뒤로 가기 액션 시 상태를 유지하도록 수정
2 parents 79cf47d + 4a87cd5 commit 5edd673

1 file changed

Lines changed: 33 additions & 8 deletions

File tree

packages/common/src/components/mdx_components/session_timetable.tsx

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Button, Chip, CircularProgress, Stack, styled, Table, TableBody, TableC
22
import { ErrorBoundary, Suspense } from "@suspensive/react";
33
import { DateTime } from "luxon";
44
import { FC, useState } from "react";
5-
import { Link } from "react-router-dom";
5+
import { Link, useLocation } from "react-router-dom";
66
import { isArray, isEmpty, isString } from "remeda";
77

88
import { CenteredPage } from "@frontend/common/components/centered_page";
@@ -110,15 +110,16 @@ const SessionColumn: FC<{
110110
colSpan?: number;
111111
session: SessionSchema;
112112
linkable?: boolean;
113-
}> = ({ rowSpan, colSpan, session, linkable }) => {
113+
selectedDate: string;
114+
}> = ({ rowSpan, colSpan, session, linkable, selectedDate }) => {
114115
const sessionUrl = linkable ? getSessionDetailUrl(session) : undefined;
115116
const clickable = isArray(session.speakers) && !isEmpty(session.speakers) && !!sessionUrl;
116117
// Firefox는 rowSpan된 td의 height를 계산할 때 rowSpan을 고려하지 않습니다. 따라서 직접 계산하여 height를 설정합니다.
117118
const sessionBoxHeight = `${TD_HEIGHT * rowSpan}rem`;
118119
return (
119120
<SessionTableCell rowSpan={rowSpan} colSpan={colSpan}>
120121
{clickable ? (
121-
<Link to={sessionUrl!} style={{ textDecoration: "none", display: "block" }}>
122+
<Link to={sessionUrl!} style={{ textDecoration: "none", display: "block" }} state={{ selectedDate: selectedDate }}>
122123
<SessionBox className="clickable" sx={{ height: sessionBoxHeight, gap: 0.75, padding: "0.5rem" }}>
123124
<SessionTitle children={session.title.replace("\\n", "\n")} align="center" />
124125
<Stack direction="row" alignItems="center" justifyContent="center" sx={{ width: "100%", flexWrap: "wrap", gap: 0.5 }}>
@@ -162,7 +163,9 @@ type SessionTimeTablePropType = {
162163
export const SessionTimeTable: FC<SessionTimeTablePropType> = ErrorBoundary.with(
163164
{ fallback: ErrorFallback },
164165
Suspense.with({ fallback: <CenteredPage children={<CircularProgress />} /> }, ({ event, types }) => {
165-
const [confDate, setConfDate] = useState("");
166+
const location = useLocation();
167+
168+
const [confDate, setConfDate] = useState<string>(location.state?.selectedDate ?? "");
166169

167170
const { language, appType } = Common.useCommonContext();
168171
const linkable = appType === "main";
@@ -176,7 +179,7 @@ export const SessionTimeTable: FC<SessionTimeTablePropType> = ErrorBoundary.with
176179
const roomCount = Object.keys(rooms).length;
177180
const sortedRoomList = Object.keys(rooms).sort();
178181

179-
const selectedDate = confDate || dates[0];
182+
const [selectedDate, setSelectedDate] = useState<string>(location.state?.selectedDate ?? (confDate || dates[0]));
180183
const selectedTableData = timeTableData[selectedDate];
181184

182185
let breakCount = 0;
@@ -194,7 +197,15 @@ export const SessionTimeTable: FC<SessionTimeTablePropType> = ErrorBoundary.with
194197
{dates.map((date, i) => {
195198
const dateStr = DateTime.fromISO(date).setLocale(language).toLocaleString({ weekday: "long", month: "long", day: "numeric" });
196199
return (
197-
<Button variant="text" key={date} onClick={() => setConfDate(date)} className={selectedDate === date ? "selected" : ""}>
200+
<Button
201+
variant="text"
202+
key={date}
203+
onClick={() => {
204+
setConfDate(date);
205+
setSelectedDate(date);
206+
}}
207+
className={selectedDate === date ? "selected" : ""}
208+
>
198209
<SessionDateItemContainer direction="column">
199210
<SessionDateTitle children={"Day " + (i + 1)} isSelected={selectedDate === date} />
200211
<SessionDateSubTitle children={dateStr} isSelected={selectedDate === date} />
@@ -277,7 +288,13 @@ export const SessionTimeTable: FC<SessionTimeTablePropType> = ErrorBoundary.with
277288
return (
278289
<SessionTableRow>
279290
<SessionTableCell align="center" children={time} />
280-
<SessionColumn rowSpan={firstSessionInfo.rowSpan} colSpan={roomCount} session={firstSessionInfo.session} linkable={linkable} />
291+
<SessionColumn
292+
rowSpan={firstSessionInfo.rowSpan}
293+
colSpan={roomCount}
294+
session={firstSessionInfo.session}
295+
linkable={linkable}
296+
selectedDate={selectedDate}
297+
/>
281298
</SessionTableRow>
282299
);
283300
}
@@ -296,7 +313,15 @@ export const SessionTimeTable: FC<SessionTimeTablePropType> = ErrorBoundary.with
296313
}
297314
// 세션이 여러 줄에 걸쳐있는 경우, n-1 줄만큼 해당 room에 column을 생성하지 않도록 합니다.
298315
if (roomDatum.rowSpan > 1) rooms[room] = roomDatum.rowSpan - 1;
299-
return <SessionColumn key={room} rowSpan={roomDatum.rowSpan} session={roomDatum.session} linkable={linkable} />;
316+
return (
317+
<SessionColumn
318+
key={room}
319+
rowSpan={roomDatum.rowSpan}
320+
session={roomDatum.session}
321+
linkable={linkable}
322+
selectedDate={selectedDate}
323+
/>
324+
);
300325
})}
301326
</SessionTableRow>
302327
);

0 commit comments

Comments
 (0)