-
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.
* feat: 에디터 및 페이지 추가 * chore: MDX 에디터 라이브러리 추가 * style: 에디터 내 마크다운 스타일을 위한 reset style 수정 * feat: 페이지 라우트 추가 * feat: 질문 모델 생성중 * feat: 에디터 추가 * fix: 질문글 폴더 구조 변경
- Loading branch information
Showing
14 changed files
with
2,914 additions
and
88 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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,13 @@ | ||
import { atom } from "recoil"; | ||
|
||
import { QuestionType } from "./question.type"; | ||
|
||
export const questionAtom = atom<QuestionType>({ | ||
key: "question", | ||
default: { | ||
title: "", | ||
language: "", | ||
purpose: "", | ||
content: "", | ||
}, | ||
}); |
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,15 @@ | ||
export type QuestionType = { | ||
title: string; | ||
language?: string; | ||
purpose: string; | ||
content: string; | ||
}; | ||
|
||
export type RegisteredQuestionType = QuestionType & { | ||
id: number; | ||
createdAt: Date; | ||
likeCount: number; | ||
viewCount: number; | ||
categories: string[]; | ||
comments: string[]; | ||
}; |
Empty file.
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,2 @@ | ||
export * from "./question.page"; | ||
export * from "./question-write.page"; |
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,5 @@ | ||
const QuestionWritePage = () => { | ||
return <div>QuestionWritePage</div>; | ||
}; | ||
|
||
export default QuestionWritePage; |
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,23 @@ | ||
import { useRef, useState } from "react"; | ||
|
||
import { MDXEditorMethods } from "@mdxeditor/editor"; | ||
|
||
import Editor from "~/shared/common-ui/editor/editor"; | ||
|
||
export const QuestionPage = () => { | ||
const ref = useRef<MDXEditorMethods>(null); | ||
const [markdown, setMarkdown] = useState<string>(""); | ||
const [content, setContent] = useState<string>(""); | ||
const handleButton = () => { | ||
if (ref.current) { | ||
setContent(ref.current.getMarkdown()); | ||
} | ||
}; | ||
return ( | ||
<div> | ||
<Editor ref={ref} onChange={(s) => setMarkdown(s)} markdown={markdown} /> | ||
<button onClick={handleButton}>{"저장"}</button> | ||
{content} | ||
</div> | ||
); | ||
}; |
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,121 @@ | ||
import { ComponentPropsWithoutRef, ElementRef, forwardRef } from "react"; | ||
|
||
import { | ||
BoldItalicUnderlineToggles, | ||
ChangeCodeMirrorLanguage, | ||
ConditionalContents, | ||
InsertCodeBlock, | ||
InsertSandpack, | ||
InsertTable, | ||
MDXEditor, | ||
SandpackConfig, | ||
ShowSandpackInfo, | ||
UndoRedo, | ||
codeBlockPlugin, | ||
codeMirrorPlugin, | ||
headingsPlugin, | ||
linkPlugin, | ||
listsPlugin, | ||
markdownShortcutPlugin, | ||
quotePlugin, | ||
sandpackPlugin, | ||
tablePlugin, | ||
thematicBreakPlugin, | ||
toolbarPlugin, | ||
} from "@mdxeditor/editor"; | ||
import "@mdxeditor/editor/style.css"; | ||
|
||
const defaultSnippetContent = ` | ||
const App = () => { | ||
return ( | ||
<div className="App"> | ||
<h1>Hello CodeSandbox</h1> | ||
<h2>Start editing to see some magic happen!</h2> | ||
</div> | ||
); | ||
} | ||
export default App; | ||
`.trim(); | ||
|
||
const simpleSandpackConfig: SandpackConfig = { | ||
defaultPreset: "react", | ||
presets: [ | ||
{ | ||
label: "React", | ||
name: "react", | ||
meta: "live react", | ||
sandpackTemplate: "react", | ||
sandpackTheme: "light", | ||
snippetFileName: "/App.js", | ||
snippetLanguage: "jsx", | ||
initialSnippetContent: defaultSnippetContent, | ||
}, | ||
], | ||
}; | ||
|
||
/* | ||
props | ||
ref | ||
현재 페이지에 보여질 상태 // | ||
변경할 setter함수 | ||
*/ | ||
|
||
type EditorProps = { | ||
markdown: string; | ||
onChange?: (str: string) => void; | ||
}; | ||
|
||
const Editor = forwardRef<ElementRef<typeof MDXEditor>, ComponentPropsWithoutRef<typeof MDXEditor> & EditorProps>( | ||
({ markdown, onChange }, ref) => { | ||
return ( | ||
<MDXEditor | ||
ref={ref} | ||
markdown={markdown} | ||
onChange={onChange} | ||
plugins={[ | ||
toolbarPlugin({ | ||
toolbarContents: () => ( | ||
<> | ||
<UndoRedo /> | ||
<BoldItalicUnderlineToggles /> | ||
<InsertTable /> | ||
<ConditionalContents | ||
options={[ | ||
{ | ||
when: (editor) => editor?.editorType === "codeblock", | ||
contents: () => <ChangeCodeMirrorLanguage />, | ||
}, | ||
{ when: (editor) => editor?.editorType === "sandpack", contents: () => <ShowSandpackInfo /> }, | ||
{ | ||
fallback: () => ( | ||
<> | ||
<InsertCodeBlock /> | ||
<InsertSandpack /> | ||
</> | ||
), | ||
}, | ||
]} | ||
/> | ||
</> | ||
), | ||
}), | ||
codeBlockPlugin({ defaultCodeBlockLanguage: "js" }), | ||
sandpackPlugin({ sandpackConfig: simpleSandpackConfig }), | ||
codeMirrorPlugin({ codeBlockLanguages: { js: "JavaScript", css: "CSS", java: "Java" } }), | ||
headingsPlugin(), | ||
listsPlugin(), | ||
tablePlugin(), | ||
linkPlugin(), | ||
quotePlugin(), | ||
markdownShortcutPlugin(), | ||
thematicBreakPlugin(), | ||
]} | ||
/> | ||
); | ||
} | ||
); | ||
|
||
Editor.displayName = "editor"; | ||
|
||
export default Editor; |
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 @@ | ||
export * from "./editor"; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./header"; | ||
export * from "./error"; | ||
export * from "./loading"; | ||
export * from "./editor"; |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
export const ROUTE = { | ||
root: "/", | ||
question: "/question", | ||
questionWrite: "/question/write", | ||
questionDetail: "/question/:id", | ||
//만약 동적인 파라미터가 필요한경우 | ||
// somethingDynamicRoute: (param:string) => `/page/${param}` | ||
}; |