diff --git a/client/components/document/index.tsx b/client/components/document/index.tsx index c3e30170..69774574 100644 --- a/client/components/document/index.tsx +++ b/client/components/document/index.tsx @@ -1,5 +1,5 @@ import { Button, ButtonGroup, Card, Input, Tabs, Textarea } from "@geist-ui/core" -import { ChangeEvent, FormEvent, memo, useEffect, useRef, useState } from "react" +import { ChangeEvent, FormEvent, memo, useEffect, useReducer, useRef, useState } from "react" import styles from './document.module.css' import MarkdownPreview from '../preview' import { Trash } from '@geist-ui/icons' @@ -16,6 +16,14 @@ type Props = { const Document = ({ remove, editable, title, content, setTitle, setContent, initialTab = 'edit' }: Props) => { const codeEditorRef = useRef(null) + const [tab, setTab] = useState(initialTab) + + const handleTabChange = (newTab: string) => { + if (newTab === 'edit') { + codeEditorRef.current?.focus() + } + setTab(newTab as 'edit' | 'preview') + } const removeFile = (remove?: () => void) => { if (remove) { @@ -47,8 +55,8 @@ const Document = ({ remove, editable, title, content, setTitle, setContent, init {remove && editable &&