diff --git a/package.json b/package.json index d1f8611..de5c24d 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "react-resizable-panels": "^0.0.33", "react-router-dom": "^6.4.5", "react-syntax-highlighter": "^15.5.0", + "remark-gfm": "^3.0.1", "uuid": "^9.0.0" }, "devDependencies": { diff --git a/src/components/Markdown/Editor.tsx b/src/components/Markdown/Editor.tsx index 2db5368..cca249d 100644 --- a/src/components/Markdown/Editor.tsx +++ b/src/components/Markdown/Editor.tsx @@ -1,21 +1,41 @@ +import { FC, useEffect, useState } from 'react'; import Editor from "@monaco-editor/react"; import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels'; +import Markdown from '@/components/Markdown'; import './index.scss'; -const MarkdownEditor = () => { +interface MarkdownEditorProps { + value?: string; + onChange?: (v: string) => void; +} + +const MarkdownEditor: FC = ({ value = '', onChange }) => { + const [content, setContent] = useState(value); + + useEffect(() => { + setContent(value); + onChange && onChange(value); + }, [value]) + + const handleEdit = (e: any) => { + setContent(e); + onChange && onChange(e); + } + return ( -
+
-
1284
+ {content}
diff --git a/src/components/Markdown/index.scss b/src/components/Markdown/index.scss index 1c5bcb0..033bd36 100644 --- a/src/components/Markdown/index.scss +++ b/src/components/Markdown/index.scss @@ -1,11 +1,24 @@ .markdown-body { + height: 100%; + overflow: auto; font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"; + + &.edit-preview { + padding: 10px; + font-size: 14px; + } + pre, code { font-family: monospace, monospace; } } +.md-main { + height: calc(100vh - 130px); + overflow: hidden; +} + .resize-handle { width: 0.25rem; transition: 250ms linear background-color; diff --git a/src/components/Markdown/index.tsx b/src/components/Markdown/index.tsx index 55bcddf..a548cc6 100644 --- a/src/components/Markdown/index.tsx +++ b/src/components/Markdown/index.tsx @@ -1,5 +1,7 @@ import { FC } from 'react'; +import clsx from 'clsx'; import ReactMarkdown from 'react-markdown'; +import remarkGfm from 'remark-gfm'; import SyntaxHighlighter from 'react-syntax-highlighter'; import agate from 'react-syntax-highlighter/dist/esm/styles/hljs/agate'; @@ -7,36 +9,40 @@ import './index.scss'; interface MarkdownProps { children: string; + className?: string; } -const Markdown: FC = ({ children }) => { +const Markdown: FC = ({ children, className }) => { return ( -
- - ) : ( - - {children} - - ) - } - }} - /> +
+
+ + ) : ( + + {children} + + ) + } + }} + /> +
) } diff --git a/src/main.scss b/src/main.scss index d94bad3..cbaf8cc 100644 --- a/src/main.scss +++ b/src/main.scss @@ -69,12 +69,11 @@ html, body { } } -.chat-file-path, -.chat-sync-path { +.chat-file-path { font-size: 12px; font-weight: 500; color: #888; - margin-bottom: 5px; + margin-bottom: 3px; line-height: 16px; > div { diff --git a/src/view/markdown/index.scss b/src/view/markdown/index.scss new file mode 100644 index 0000000..3b61798 --- /dev/null +++ b/src/view/markdown/index.scss @@ -0,0 +1,15 @@ + +.md-task { + margin-bottom: 5px; + + .ant-breadcrumb-link { + padding: 3px 5px; + transition: all 300ms ease; + border-radius: 4px; + &:hover { + color: rgba(0, 0, 0, 0.88); + background-color: rgba(0, 0, 0, 0.06); + cursor: pointer; + } + } +} \ No newline at end of file diff --git a/src/view/markdown/index.tsx b/src/view/markdown/index.tsx index e80f2b4..ed1a165 100644 --- a/src/view/markdown/index.tsx +++ b/src/view/markdown/index.tsx @@ -3,30 +3,41 @@ import { useLocation } from 'react-router-dom'; import { Breadcrumb } from 'antd'; import { ArrowLeftOutlined } from '@ant-design/icons'; import MarkdownEditor from '@/components/Markdown/Editor'; +import { fs, shell } from '@tauri-apps/api'; import useInit from '@/hooks/useInit'; import { getPath } from '@/view/notes/config'; +import './index.scss'; export default function Markdown() { const [filePath, setFilePath] = useState(''); + const [source, setSource] = useState(''); const location = useLocation(); const state = location?.state; useInit(async () => { - setFilePath(await getPath(state)); + const file = await getPath(state); + setFilePath(file); + setSource(await fs.readTextFile(file)) }) + const handleChange = async (v: string) => { + await fs.writeTextFile(filePath, v); + }; + return ( <> - - - - - - {filePath} - - - +
+ + history.go(-1)}> + + + shell.open(filePath)}> + {filePath} + + +
+ ); } \ No newline at end of file