diff --git a/src/components/EditorPage/MdEditor.jsx b/src/components/EditorPage/MdEditor.jsx index e69de29..22e0117 100644 --- a/src/components/EditorPage/MdEditor.jsx +++ b/src/components/EditorPage/MdEditor.jsx @@ -0,0 +1,105 @@ +import React, { useEffect, useState } from "react"; +import PostTitle from "./PostTitle"; +import EditerFooter from "./EditorFooter"; +import Dropdown from "./Dropdown"; +import MDEditor from "@uiw/react-md-editor/nohighlight"; +import "@uiw/react-md-editor/markdown-editor.css"; +import "@uiw/react-markdown-preview/markdown.css"; +import "../../styles/Editor.css"; +import { getAlgorithms } from "../../api/detail"; + +function MdEditor() { + const [postData, setPostData] = useState({ + language: "언어", + site: "사이트", + algorithmId: 1, + title: "제목", + tag: "태그", + link: "링크", + codeContent: "코드", + content: "내용", + }); + const [algorithmOptions, setAlgorithmOptions] = useState([]); + const algorithmNames = algorithmOptions.map((item) => item.korClassification); + + const handleDrop = async (event) => { + event.preventDefault(); + const files = event.dataTransfer.files; + if (files.length > 0) { + const file = files[0]; + const reader = new FileReader(); + reader.onload = (e) => { + const imageUrl = e.target.result; + setPostData((prev) => `${prev}\n![image](${imageUrl})`); + }; + reader.readAsDataURL(file); + } + }; + + useEffect(() => { + getAlgorithms().then((res) => setAlgorithmOptions(res.data.algorithmList)); + }, []); + + return ( +
e.preventDefault()} + > +
+ setPostData({ ...postData, title: e.target.value })} + /> +
+ setPostData({ ...postData, site: e.target.value })} + /> + + setPostData({ ...postData, language: e.target.value }) + } + /> + + setPostData({ ...postData, algorithmId: Number(e.target.value) }) + } + /> +
+ setPostData({ ...postData, content: value })} + preview="edit" + textareaProps={{ + placeholder: "내용을 입력하세요.", + }} + /> + +
+
+
+ +
+
+
+ ); +} + +export default MdEditor;