|
| 1 | +import * as React from "react"; |
| 2 | +import * as R from "remeda"; |
| 3 | + |
| 4 | +import { Button, CircularProgress, MenuItem, Select, Stack } from '@mui/material'; |
| 5 | +import { ErrorBoundary, Suspense } from '@suspensive/react'; |
| 6 | + |
| 7 | +import * as Common from "@frontend/common"; |
| 8 | + |
| 9 | +const SiteMapRenderer: React.FC = () => { |
| 10 | + const { data } = Common.Hooks.BackendAPI.useFlattenSiteMapQuery(); |
| 11 | + return <pre style={{ whiteSpace: "pre-wrap" }}>{JSON.stringify(Common.Utils.buildNestedSiteMap(data), null, 2)}</pre> |
| 12 | +}; |
| 13 | + |
| 14 | +const PageIdSelector: React.FC<{ inputRef: React.Ref<HTMLSelectElement> }> = ({ inputRef }) => { |
| 15 | + const { data } = Common.Hooks.BackendAPI.useFlattenSiteMapQuery(); |
| 16 | + |
| 17 | + return <Select inputRef={inputRef}> |
| 18 | + {data.map((siteMap) => <MenuItem key={siteMap.id} value={siteMap.page}>{siteMap.name}</MenuItem>)} |
| 19 | + </Select> |
| 20 | +} |
| 21 | + |
| 22 | +const SuspenseWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => ( |
| 23 | + <ErrorBoundary fallback={Common.Components.ErrorFallback}> |
| 24 | + <Suspense fallback={<CircularProgress />}> |
| 25 | + {children} |
| 26 | + </Suspense> |
| 27 | + </ErrorBoundary> |
| 28 | +) |
| 29 | + |
| 30 | +export const BackendTestPage: React.FC = () => { |
| 31 | + const inputRef = React.useRef<HTMLSelectElement>(null); |
| 32 | + const [pageId, setPageId] = React.useState<string | null>(null); |
| 33 | + |
| 34 | + return <Stack> |
| 35 | + <br /> |
| 36 | + <SuspenseWrapper><SiteMapRenderer /></SuspenseWrapper> |
| 37 | + <br /> |
| 38 | + <SuspenseWrapper><PageIdSelector inputRef={inputRef} /></SuspenseWrapper> |
| 39 | + <br /> |
| 40 | + <Button variant="outlined" onClick={() => setPageId(inputRef.current?.value ?? null)}>페이지 렌더링</Button> |
| 41 | + <br /> |
| 42 | + {R.isString(pageId) ? <SuspenseWrapper><Common.Components.PageRenderer id={pageId} /></SuspenseWrapper> : <>페이지를 선택해주세요.</>} |
| 43 | + </Stack> |
| 44 | +} |
0 commit comments