Skip to content

Commit 2bc29fb

Browse files
committed
chore: MDX 테스트 페이지가 MDXEditor를 사용하도록 수정
1 parent 3028dfe commit 2bc29fb

File tree

1 file changed

+11
-30
lines changed

1 file changed

+11
-30
lines changed
Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,24 @@
11
import React from "react";
22

3-
import { Box, Button, Stack } from "@mui/material";
3+
import { Box, Stack } from "@mui/material";
44

5-
import { MDX_HELP_TEXT } from "@apps/pyconkr/consts/mdx_help_text";
65
import * as Common from "@frontend/common";
76

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%" };
198

209
export const MdiTestPage: React.FC = () => {
2110
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+
}
2817

2918
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>
4122
</Stack>
4223
);
4324
};

0 commit comments

Comments
 (0)