mirror of
https://github.com/usememos/memos.git
synced 2025-02-20 21:30:55 +01:00
chore: retire preview markdown dialog
This commit is contained in:
parent
4ad6028681
commit
61b8cee31d
@ -1,8 +1,6 @@
|
||||
import { Dropdown, IconButton, Menu, MenuButton, MenuItem } from "@mui/joy";
|
||||
import { Link } from "@mui/joy";
|
||||
import toast from "react-hot-toast";
|
||||
import Icon from "@/components/Icon";
|
||||
import showPreviewMarkdownDialog from "@/components/PreviewMarkdownDialog";
|
||||
import { EditorRefActions } from "../Editor";
|
||||
|
||||
interface Props {
|
||||
@ -59,16 +57,6 @@ const MarkdownMenu = (props: Props) => {
|
||||
});
|
||||
};
|
||||
|
||||
const handlePreviewClick = () => {
|
||||
const content = editorRef.current?.getContent() ?? "";
|
||||
if (content === "") {
|
||||
toast.error("Nothing to preview");
|
||||
return;
|
||||
}
|
||||
|
||||
showPreviewMarkdownDialog(editorRef.current?.getContent() ?? "");
|
||||
};
|
||||
|
||||
return (
|
||||
<Dropdown>
|
||||
<MenuButton
|
||||
@ -90,10 +78,6 @@ const MarkdownMenu = (props: Props) => {
|
||||
<Icon.CheckSquare className="w-4 h-auto" />
|
||||
<span>Checkbox</span>
|
||||
</MenuItem>
|
||||
<MenuItem onClick={handlePreviewClick}>
|
||||
<Icon.GanttChartSquare className="w-4 h-auto" />
|
||||
<span>Preview</span>
|
||||
</MenuItem>
|
||||
<div className="-mt-0.5 pl-2">
|
||||
<Link fontSize={12} href="https://www.usememos.com/docs/getting-started/content-syntax" target="_blank">
|
||||
Content syntax
|
||||
|
@ -1,59 +0,0 @@
|
||||
import { IconButton } from "@mui/joy";
|
||||
import { useEffect, useState } from "react";
|
||||
import { markdownServiceClient } from "@/grpcweb";
|
||||
import { Node } from "@/types/proto/api/v1/markdown_service";
|
||||
import { generateDialog } from "./Dialog";
|
||||
import Icon from "./Icon";
|
||||
import MemoContent from "./MemoContent";
|
||||
|
||||
interface Props extends DialogProps {
|
||||
content: string;
|
||||
}
|
||||
|
||||
const PreviewMarkdownDialog: React.FC<Props> = ({ content, destroy }: Props) => {
|
||||
const [nodes, setNodes] = useState<Node[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
const { nodes } = await markdownServiceClient.parseMarkdown({ markdown: content });
|
||||
setNodes(nodes);
|
||||
} catch (error) {
|
||||
console.error("Error parsing markdown:", error);
|
||||
}
|
||||
})();
|
||||
}, [content]);
|
||||
|
||||
const handleCloseBtnClick = () => {
|
||||
destroy();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="dialog-header-container">
|
||||
<div className="flex flex-row justify-start items-center">
|
||||
<p className="text-black opacity-80 dark:text-gray-200">Preview</p>
|
||||
</div>
|
||||
<IconButton size="sm" onClick={handleCloseBtnClick}>
|
||||
<Icon.X className="w-5 h-auto" />
|
||||
</IconButton>
|
||||
</div>
|
||||
<div className="flex flex-col justify-start items-start max-w-full w-[32rem]">
|
||||
{nodes.length > 0 ? <MemoContent nodes={nodes} /> : <p className="text-gray-400 dark:text-gray-600">Nothing to preview</p>}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default function showPreviewMarkdownDialog(content: string): void {
|
||||
generateDialog(
|
||||
{
|
||||
className: "preview-markdown-dialog",
|
||||
dialogName: "preview-markdown-dialog",
|
||||
},
|
||||
PreviewMarkdownDialog,
|
||||
{
|
||||
content,
|
||||
},
|
||||
);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user