-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`); | ||
}; | ||
reader.readAsDataURL(file); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
getAlgorithms().then((res) => setAlgorithmOptions(res.data.algorithmList)); | ||
}, []); | ||
|
||
return ( | ||
<div | ||
className="flex h-screen" | ||
data-color-mode="light" | ||
onDrop={handleDrop} | ||
onDragOver={(e) => e.preventDefault()} | ||
> | ||
<div className="flex flex-col w-full h-full sm:w-1/2"> | ||
<PostTitle | ||
title={postData?.title} | ||
onChange={(e) => setPostData({ ...postData, title: e.target.value })} | ||
/> | ||
<div className="flex px-1 m-3 space-x-2"> | ||
<Dropdown | ||
name="site" | ||
value={postData?.site} | ||
options={["백준", "Programmers", "SWEA", "민코딩"]} | ||
placeholder="SITE" | ||
onChange={(e) => setPostData({ ...postData, site: e.target.value })} | ||
/> | ||
<Dropdown | ||
name="language" | ||
value={postData?.language} | ||
options={["C", "Java", "Python"]} | ||
placeholder="언어" | ||
onChange={(e) => | ||
setPostData({ ...postData, language: e.target.value }) | ||
} | ||
/> | ||
<Dropdown | ||
name="algorithm" | ||
value={algorithmNames[postData.algorithmId - 1]} | ||
options={algorithmNames} | ||
placeholder="알고리즘" | ||
onChange={(e) => | ||
setPostData({ ...postData, algorithmId: Number(e.target.value) }) | ||
} | ||
/> | ||
</div> | ||
<MDEditor | ||
height="100%" | ||
value={postData?.content} | ||
onChange={(value) => setPostData({ ...postData, content: value })} | ||
preview="edit" | ||
textareaProps={{ | ||
placeholder: "내용을 입력하세요.", | ||
}} | ||
/> | ||
<EditerFooter /> | ||
</div> | ||
<div className="flex-col hidden w-1/2 h-full p-3 overflow-auto sm:flex bg-sky-50"> | ||
<div className="preview-content"> | ||
<MDEditor.Markdown | ||
source={`# ${postData.title}\n${postData.content}`} | ||
style={{ whiteSpace: "pre-wrap" }} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default MdEditor; |