From 3c5dcc24ac4b67a0bdcbad1ae049ca1838f33ed5 Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Wed, 16 Nov 2022 00:49:12 -0800 Subject: [PATCH] Custom tabs --- .../app/(posts)/components/preview/index.tsx | 17 ++-- client/app/(posts)/components/tabs/index.tsx | 84 +++++++++++++++++ .../(posts)/components/tabs/tabs.module.css | 42 +++++++++ .../new/components/description/index.tsx | 2 +- .../drag-and-drop/drag-and-drop.module.css | 7 +- .../edit-document/index.tsx | 88 +++++------------- client/app/(posts)/new/components/new.tsx | 5 +- .../(posts)/new/components/title/index.tsx | 26 +++--- .../post-page/view-document/index.tsx | 83 +++-------------- .../button-group/button-group.module.css | 8 +- client/app/components/home.tsx | 30 +++---- client/app/components/input/index.tsx | 21 ++++- client/app/components/input/input.module.css | 90 ++++++++++--------- client/app/styles/globals.css | 20 ++++- client/package.json | 1 + client/pnpm-lock.yaml | 65 ++++++++++++++ 16 files changed, 356 insertions(+), 233 deletions(-) create mode 100644 client/app/(posts)/components/tabs/index.tsx create mode 100644 client/app/(posts)/components/tabs/tabs.module.css diff --git a/client/app/(posts)/components/preview/index.tsx b/client/app/(posts)/components/preview/index.tsx index d9a30610..5fe9b75d 100644 --- a/client/app/(posts)/components/preview/index.tsx +++ b/client/app/(posts)/components/preview/index.tsx @@ -14,10 +14,10 @@ type Props = { const MarkdownPreview = ({ height = 500, fileId, - content: initial = "", + content = "", title }: Props) => { - const [content, setPreview] = useState(initial) + const [preview, setPreview] = useState(content) const [isLoading, setIsLoading] = useState(true) useEffect(() => { async function fetchPost() { @@ -28,7 +28,7 @@ const MarkdownPreview = ({ ? undefined : JSON.stringify({ title: title || "", - content: initial + content: content }) const resp = await fetch(path, { @@ -47,14 +47,14 @@ const MarkdownPreview = ({ setIsLoading(false) } fetchPost() - }, [initial, fileId, title]) + }, [content, fileId, title]) return ( <> {isLoading ? ( <> ) : ( - + )} ) @@ -63,16 +63,17 @@ const MarkdownPreview = ({ export default memo(MarkdownPreview) export const StaticPreview = ({ - content, + preview, height = 500 }: { - content: string + preview: string height: string | number }) => { + console.log("content", preview) return (
) => void + onPaste?: (e: any) => void + title?: string + content?: string + preview?: string +} + +export default function DocumentTabs({ + isEditing, + defaultTab, + handleOnContentChange, + onPaste, + title, + content, + preview, + ...props +}: Props) { + const codeEditorRef = useRef(null) + + const handleTabChange = (newTab: string) => { + if (newTab === "preview") { + codeEditorRef.current?.focus() + } + } + + return ( + + + + {isEditing ? "Edit" : "Raw"} + + + {isEditing ? "Preview" : "Rendered"} + + + + +
+ + */} -
- - */} -
-