|
| 1 | +import * as Common from "@frontend/common"; |
| 2 | +import { Box, Chip, CircularProgress, Divider, Stack, styled, Typography } from "@mui/material"; |
| 3 | +import { ErrorBoundary, Suspense } from "@suspensive/react"; |
| 4 | +import * as React from "react"; |
| 5 | +import { useParams } from "react-router-dom"; |
| 6 | +import * as R from "remeda"; |
| 7 | + |
| 8 | +import BackendAPISchemas from "../../../../../packages/common/src/schemas/backendAPI"; |
| 9 | +import { useAppContext } from "../../contexts/app_context"; |
| 10 | +import { PageLayout } from "../layout/PageLayout"; |
| 11 | + |
| 12 | +const PageNotFound: React.FC = () => <>404 Not Found</>; |
| 13 | +const CenteredLoadingPage: React.FC = () => ( |
| 14 | + <Common.Components.CenteredPage> |
| 15 | + <CircularProgress /> |
| 16 | + </Common.Components.CenteredPage> |
| 17 | +); |
| 18 | + |
| 19 | +const LogoImage = styled("img")(({ theme }) => ({ |
| 20 | + maxWidth: "20rem", |
| 21 | + height: "auto", |
| 22 | + |
| 23 | + padding: theme.spacing(8, 0), |
| 24 | + marginBottom: theme.spacing(4), |
| 25 | + |
| 26 | + [theme.breakpoints.down("lg")]: { |
| 27 | + padding: theme.spacing(4), |
| 28 | + }, |
| 29 | + [theme.breakpoints.down("sm")]: { |
| 30 | + padding: theme.spacing(2), |
| 31 | + }, |
| 32 | +})); |
| 33 | + |
| 34 | +const DescriptionBox = styled(Box)(({ theme }) => ({ |
| 35 | + width: "100%", |
| 36 | + padding: theme.spacing(2, 4), |
| 37 | + |
| 38 | + [theme.breakpoints.down("lg")]: { |
| 39 | + padding: theme.spacing(2), |
| 40 | + }, |
| 41 | + [theme.breakpoints.down("sm")]: { |
| 42 | + padding: theme.spacing(1), |
| 43 | + }, |
| 44 | + |
| 45 | + "& .markdown-body": { |
| 46 | + width: "100%", |
| 47 | + p: { margin: theme.spacing(2, 0) }, |
| 48 | + }, |
| 49 | +})); |
| 50 | + |
| 51 | +export const SponsorDetailPage: React.FC = ErrorBoundary.with( |
| 52 | + { fallback: Common.Components.ErrorFallback }, |
| 53 | + Suspense.with({ fallback: <CenteredLoadingPage /> }, () => { |
| 54 | + const { id } = useParams(); |
| 55 | + const { language, sponsorTiers, setAppContext } = useAppContext(); |
| 56 | + const sponsors = sponsorTiers?.reduce((acc, tier) => [...acc, ...tier.sponsors], [] as BackendAPISchemas.SponsorTierSchema["sponsors"]); |
| 57 | + const sponsor = sponsors?.find((s) => s.id === id); |
| 58 | + |
| 59 | + const title = language === "ko" ? "후원사" : "Sponsor"; |
| 60 | + const descriptionFallback = language === "ko" ? "해당 후원사의 설명은 준비 중이에요!" : "This sponsor's description is under preparation!"; |
| 61 | + |
| 62 | + React.useEffect(() => { |
| 63 | + setAppContext((prev) => ({ |
| 64 | + ...prev, |
| 65 | + title: `${title} - ${sponsor?.name || "Detail"}`, |
| 66 | + shouldShowTitleBanner: true, |
| 67 | + shouldShowSponsorBanner: !R.isNonNullish(sponsor), |
| 68 | + })); |
| 69 | + }, [sponsor, title, setAppContext]); |
| 70 | + |
| 71 | + if (!id || !sponsorTiers) return <CenteredLoadingPage />; |
| 72 | + if (!sponsor) return <PageNotFound />; |
| 73 | + |
| 74 | + return ( |
| 75 | + <PageLayout sx={{ maxWidth: "960px" }}> |
| 76 | + <LogoImage src={sponsor.logo} alt={sponsor.name} loading="lazy" /> |
| 77 | + <Divider flexItem /> |
| 78 | + <Typography variant="h4" fontWeight="700" textAlign="start" sx={{ width: "100%", p: 2 }}> |
| 79 | + {sponsor.name.replace(/\\n/g, "\n")} |
| 80 | + {sponsor.tags.length ? ( |
| 81 | + <Stack direction="row" spacing={1} sx={{ width: "100%", mt: 1 }} aria-label="후원사 태그 목록"> |
| 82 | + {sponsor.tags.map((tag) => ( |
| 83 | + <Chip key={tag} size="small" variant="outlined" color="primary" label={tag} /> |
| 84 | + ))} |
| 85 | + </Stack> |
| 86 | + ) : null} |
| 87 | + </Typography> |
| 88 | + <Divider flexItem /> |
| 89 | + <DescriptionBox> |
| 90 | + <Common.Components.MDXRenderer text={sponsor.description || descriptionFallback} format="md" /> |
| 91 | + </DescriptionBox> |
| 92 | + </PageLayout> |
| 93 | + ); |
| 94 | + }) |
| 95 | +); |
0 commit comments