Skip to content

Commit de31dd0

Browse files
Yushin-Lclaude
andcommitted
Add editor/markdown toggle in write page
- Toggle buttons to switch between WYSIWYG and Markdown mode - Markdown mode: monospace textarea for raw markdown editing - Both modes share the same body state (stored as markdown) - Image upload adapts to current mode Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 340ecd9 commit de31dd0

1 file changed

Lines changed: 45 additions & 5 deletions

File tree

src/app/write/page.tsx

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function WritePage() {
2626
const [saving, setSaving] = useState(false);
2727
const [publishing, setPublishing] = useState(false);
2828
const [message, setMessage] = useState("");
29+
const [mdMode, setMdMode] = useState(false);
2930
const editorRef = useRef<any>(null);
3031

3132
useEffect(() => {
@@ -201,15 +202,54 @@ function WritePage() {
201202

202203
<TagInput value={tagsInput} onChange={setTagsInput} />
203204

204-
<NovelEditor key={currentDraft?.id ?? "new"} value={body} onChange={setBody} editorRef={editorRef} />
205+
{/* 에디터 모드 토글 */}
206+
<div className="flex items-center gap-2">
207+
<button
208+
type="button"
209+
onClick={() => setMdMode(false)}
210+
className={`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors ${
211+
!mdMode
212+
? "bg-indigo-600 text-white"
213+
: "bg-stone-100 text-stone-500 hover:bg-stone-200"
214+
}`}
215+
>
216+
에디터
217+
</button>
218+
<button
219+
type="button"
220+
onClick={() => setMdMode(true)}
221+
className={`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors ${
222+
mdMode
223+
? "bg-indigo-600 text-white"
224+
: "bg-stone-100 text-stone-500 hover:bg-stone-200"
225+
}`}
226+
>
227+
Markdown
228+
</button>
229+
</div>
230+
231+
{mdMode ? (
232+
<textarea
233+
value={body}
234+
onChange={(e) => setBody(e.target.value)}
235+
placeholder="마크다운으로 작성하세요..."
236+
className="min-h-[400px] w-full resize-y rounded-lg border border-stone-300 bg-white p-6 font-mono text-sm text-stone-800 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500"
237+
/>
238+
) : (
239+
<NovelEditor key={currentDraft?.id ?? "new"} value={body} onChange={setBody} editorRef={editorRef} />
240+
)}
205241

206242
<ImageUpload
207243
onUploaded={(url) => {
208-
const editor = editorRef.current;
209-
if (editor) {
210-
editor.chain().focus().setImage({ src: url, alt: "이미지" }).run();
211-
} else {
244+
if (mdMode) {
212245
setBody((prev) => prev + `\n![이미지](${url})\n`);
246+
} else {
247+
const editor = editorRef.current;
248+
if (editor) {
249+
editor.chain().focus().setImage({ src: url, alt: "이미지" }).run();
250+
} else {
251+
setBody((prev) => prev + `\n![이미지](${url})\n`);
252+
}
213253
}
214254
}}
215255
/>

0 commit comments

Comments
 (0)