|
1 | 1 | import React from "react"; |
2 | 2 |
|
3 | | -import { Box, Button, Stack } from "@mui/material"; |
| 3 | +import { Box, Stack } from "@mui/material"; |
4 | 4 |
|
5 | | -import { MDX_HELP_TEXT } from "@apps/pyconkr/consts/mdx_help_text"; |
6 | 5 | import * as Common from "@frontend/common"; |
7 | 6 |
|
8 | | -const LOCAL_STEORAGE_KEY = "mdi_test_input"; |
9 | | - |
10 | | -const getMdxInputFromLocalStorage: () => string = () => { |
11 | | - const input = localStorage.getItem(LOCAL_STEORAGE_KEY); |
12 | | - return input ? input : ""; |
13 | | -} |
14 | | - |
15 | | -const setMdxInputToLocalStorage: (input: string) => string = (input) => { |
16 | | - localStorage.setItem(LOCAL_STEORAGE_KEY, input); |
17 | | - return input; |
18 | | -} |
| 7 | +const HalfWidthStyle: React.CSSProperties = { width: "50%", maxWidth: "50%" }; |
19 | 8 |
|
20 | 9 | export const MdiTestPage: React.FC = () => { |
21 | 10 | const inputRef = React.useRef<HTMLTextAreaElement>(null); |
22 | | - const [state, setState] = React.useState<{ text: string, resetKey: number }>({ |
23 | | - text: getMdxInputFromLocalStorage(), |
24 | | - resetKey: Math.random() |
25 | | - }); |
26 | | - |
27 | | - const setMDXInput = (text: string) => setState({ text: setMdxInputToLocalStorage(text), resetKey: Math.random() }); |
| 11 | + const [state, setState] = React.useState<{ text: string, resetKey: number }>({ text: "", resetKey: Math.random() }); |
| 12 | + const setMDXInput = (text: string) => setState({ text, resetKey: Math.random() }); |
| 13 | + const onLoad = (text: string) => { |
| 14 | + setState((prev) => ({ ...prev, text })); |
| 15 | + if (inputRef.current) inputRef.current.value = text; |
| 16 | + } |
28 | 17 |
|
29 | 18 | return ( |
30 | | - <Stack direction="row" spacing={2} sx={{ width: "100%", flexGrow: 1, p: 2 }}> |
31 | | - <Stack direction="column" spacing={2} sx={{ width: "50%", maxWidth: "50%" }}> |
32 | | - <textarea ref={inputRef} defaultValue={state.text} style={{ flexGrow: 1 }} /> |
33 | | - <Stack direction="column" spacing={2} sx={{ mb: 2 }}> |
34 | | - <Button variant="contained" sx={{ flexGrow: 1 }} onClick={() => inputRef.current && setMDXInput(inputRef.current.value)}>변환</Button> |
35 | | - <Button variant="contained" sx={{ flexGrow: 1 }} onClick={() => setMDXInput(MDX_HELP_TEXT)}>Help Text 로딩</Button> |
36 | | - </Stack> |
37 | | - </Stack> |
38 | | - <Box sx={{ width: "50%", maxWidth: "50%", overflowY: "scroll" }}> |
39 | | - <Common.Components.MDXRenderer {...state} /> |
40 | | - </Box> |
| 19 | + <Stack direction="row" spacing={2} sx={{ width: "100%", height: "100%", minHeight: "100%", maxHeight: "100%", flexGrow: 1, py: 2 }}> |
| 20 | + <Box sx={HalfWidthStyle}><Common.Components.MDXEditor inputRef={inputRef} defaultValue={state.text} onLoad={onLoad} onSave={setMDXInput} ctrlSMode="save" /></Box> |
| 21 | + <Box sx={HalfWidthStyle}><Common.Components.MDXRenderer {...state} /></Box> |
41 | 22 | </Stack> |
42 | 23 | ); |
43 | 24 | }; |
0 commit comments