|
| 1 | +import { useBackendClient, useSessionsQuery } from "@frontend/common/hooks/useAPI"; |
| 2 | +import { getSessionDetailUrl } from "@frontend/common/utils"; |
| 3 | +import { useShopClient, useUserStatus } from "@frontend/shop/hooks"; |
| 4 | +import { Button, CircularProgress, Stack, Typography } from "@mui/material"; |
| 5 | +import { FC, useEffect, useMemo } from "react"; |
| 6 | +import { Link as RouterLink } from "react-router-dom"; |
| 7 | + |
| 8 | +import { PageLayout } from "@apps/pyconkr-2026/components/layout/PageLayout"; |
| 9 | +import { EVENT_NAME } from "@apps/pyconkr-2026/consts"; |
| 10 | +import { useAppContext } from "@apps/pyconkr-2026/contexts/app_context"; |
| 11 | +import { MyTimetableGrid, TimetablePlacement, TRACKS } from "@apps/pyconkr-2026/features/schedule/my_timetable_grid"; |
| 12 | +import { useMyScheduleQuery } from "@apps/pyconkr-2026/features/schedule/use_my_schedule"; |
| 13 | + |
| 14 | +export const MyTimetablePage: FC = () => { |
| 15 | + const { language, setAppContext } = useAppContext(); |
| 16 | + const isKo = language === "ko"; |
| 17 | + const backendClient = useBackendClient(); |
| 18 | + const { data: user } = useUserStatus(useShopClient()); |
| 19 | + const isAuthenticated = user?.meta.is_authenticated === true; |
| 20 | + const { data: sessions } = useSessionsQuery(backendClient, { event: EVENT_NAME, types: "세션" }); |
| 21 | + const eventId = sessions[0]?.presentation_type.event.id; |
| 22 | + const { data: bookmarks, isLoading } = useMyScheduleQuery(backendClient, eventId, isAuthenticated); |
| 23 | + const placements = useMemo(() => { |
| 24 | + const selectedIds = new Set(bookmarks?.presentation_ids ?? []); |
| 25 | + return sessions.flatMap((session) => |
| 26 | + selectedIds.has(session.id) |
| 27 | + ? (session.room_schedules.length === TRACKS.length ? session.room_schedules.slice(0, 1) : session.room_schedules).flatMap( |
| 28 | + (schedule): TimetablePlacement[] => { |
| 29 | + const track = TRACKS.find(({ roomOrder }) => roomOrder === schedule.room_order); |
| 30 | + const startMs = Date.parse(schedule.start_at); |
| 31 | + const endMs = Date.parse(schedule.end_at); |
| 32 | + if (!track || !Number.isFinite(startMs) || !Number.isFinite(endMs) || startMs >= endMs) return []; |
| 33 | + return [ |
| 34 | + { |
| 35 | + key: `${session.id}:${schedule.id}`, |
| 36 | + trackKey: track.key, |
| 37 | + startMs, |
| 38 | + endMs, |
| 39 | + title: session.title, |
| 40 | + speakers: session.speakers.map(({ nickname }) => nickname).join(", ") || undefined, |
| 41 | + href: getSessionDetailUrl(session), |
| 42 | + trackSpan: session.room_schedules.length === TRACKS.length ? TRACKS.length : undefined, |
| 43 | + }, |
| 44 | + ]; |
| 45 | + } |
| 46 | + ) |
| 47 | + : [] |
| 48 | + ); |
| 49 | + }, [bookmarks, sessions]); |
| 50 | + |
| 51 | + useEffect(() => { |
| 52 | + setAppContext((prev) => ({ |
| 53 | + ...prev, |
| 54 | + title: isKo ? "내 시간표" : "My Schedule", |
| 55 | + shouldShowTitleBanner: true, |
| 56 | + shouldShowSponsorBanner: false, |
| 57 | + })); |
| 58 | + }, [isKo, setAppContext]); |
| 59 | + |
| 60 | + if (!isAuthenticated) { |
| 61 | + return ( |
| 62 | + <PageLayout> |
| 63 | + <Stack alignItems="center" spacing={2} sx={{ py: 6, textAlign: "center" }}> |
| 64 | + <Typography variant="h5" fontWeight={800} children={isKo ? "로그인이 필요해요" : "Sign in required"} /> |
| 65 | + <Typography |
| 66 | + color="text.secondary" |
| 67 | + children={isKo ? "나의 세션 시간표를 보려면 로그인해 주세요." : "Sign in to view your session schedule."} |
| 68 | + /> |
| 69 | + <Button component={RouterLink} to="/account/sign-in" variant="contained" children={isKo ? "로그인하기" : "Sign in"} /> |
| 70 | + </Stack> |
| 71 | + </PageLayout> |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + if (isLoading) { |
| 76 | + return ( |
| 77 | + <PageLayout> |
| 78 | + <Stack alignItems="center" sx={{ py: 6 }}> |
| 79 | + <CircularProgress /> |
| 80 | + </Stack> |
| 81 | + </PageLayout> |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + return ( |
| 86 | + <PageLayout> |
| 87 | + <MyTimetableGrid placements={placements} /> |
| 88 | + </PageLayout> |
| 89 | + ); |
| 90 | +}; |
0 commit comments