diff --git a/web/src/components/MemoActionMenu.tsx b/web/src/components/MemoActionMenu.tsx index b1d44f2e..6a8471b5 100644 --- a/web/src/components/MemoActionMenu.tsx +++ b/web/src/components/MemoActionMenu.tsx @@ -15,6 +15,7 @@ interface Props { memo: Memo; className?: string; hiddenActions?: ("edit" | "archive" | "delete" | "share" | "pin")[]; + onEdit?: () => void; } const MemoActionMenu = (props: Props) => { @@ -50,6 +51,12 @@ const MemoActionMenu = (props: Props) => { }; const handleEditMemoClick = () => { + if (props.onEdit) { + props.onEdit(); + return; + } + + // TODO: remove me later. showMemoEditorDialog({ memoName: memo.name, cacheKey: `${memo.name}-${memo.updateTime}`, diff --git a/web/src/components/MemoEditor/index.tsx b/web/src/components/MemoEditor/index.tsx index f35f5ea0..a728a8da 100644 --- a/web/src/components/MemoEditor/index.tsx +++ b/web/src/components/MemoEditor/index.tsx @@ -38,6 +38,7 @@ export interface Props { autoFocus?: boolean; memoPatchRef?: React.MutableRefObject>; onConfirm?: (memoName: string) => void; + onCancel?: () => void; } interface State { @@ -439,7 +440,12 @@ const MemoEditor = (props: Props) => { ))} -
+
+ {props.onCancel && ( + + )}
)}
-
-
- {props.showVisibility && memo.visibility !== Visibility.PRIVATE && ( - - - - + {!showEditor && ( +
+
+ {props.showVisibility && memo.visibility !== Visibility.PRIVATE && ( + + + + + + )} + {currentUser && } +
+ {!isInMemoDetailPage && ( + + + {commentAmount > 0 && {commentAmount}} + + )} + {props.showPinned && memo.pinned && ( + + )} - {currentUser && } + {!readonly && ( + setShowEditor(true)} + /> + )}
- {!isInMemoDetailPage && ( - - - {commentAmount > 0 && {commentAmount}} - - )} - {props.showPinned && memo.pinned && ( - - - - )} - {!readonly && } -
+ )}
- - - - + + {showEditor ? ( + setShowEditor(false)} + onCancel={() => setShowEditor(false)} + /> + ) : ( + <> + + + + + + )} ); }; diff --git a/web/src/pages/MemoDetail.tsx b/web/src/pages/MemoDetail.tsx index cc3d15da..7f44f737 100644 --- a/web/src/pages/MemoDetail.tsx +++ b/web/src/pages/MemoDetail.tsx @@ -6,7 +6,7 @@ import { toast } from "react-hot-toast"; import { Link, useParams } from "react-router-dom"; import Icon from "@/components/Icon"; import { MemoDetailSidebar, MemoDetailSidebarDrawer } from "@/components/MemoDetailSidebar"; -import showMemoEditorDialog from "@/components/MemoEditor/MemoEditorDialog"; +import MemoEditor from "@/components/MemoEditor"; import MemoView from "@/components/MemoView"; import MobileHeader from "@/components/MobileHeader"; import useCurrentUser from "@/hooks/useCurrentUser"; @@ -27,6 +27,7 @@ const MemoDetail = () => { const uid = params.uid; const memo = memoStore.getMemoByUid(uid || ""); const [parentMemo, setParentMemo] = useState(undefined); + const [showCommentEditor, setShowCommentEditor] = useState(false); const commentRelations = memo?.relations.filter((relation) => relation.relatedMemo === memo.name && relation.type === MemoRelation_Type.COMMENT) || []; const comments = commentRelations.map((relation) => memoStore.getMemoByName(relation.memo)).filter((memo) => memo) as any as Memo[]; @@ -66,17 +67,13 @@ const MemoDetail = () => { } const handleShowCommentEditor = () => { - showMemoEditorDialog({ - placeholder: t("editor.add-your-comment-here"), - parentMemoName: memo.name, - onConfirm: handleCommentCreated, - cacheKey: `${memo.name}-${memo.updateTime}-comment`, - }); + setShowCommentEditor(true); }; const handleCommentCreated = async (memoCommentName: string) => { await memoStore.getOrFetchMemoByName(memoCommentName); await memoStore.getOrFetchMemoByName(memo.name, { skipCache: true }); + setShowCommentEditor(false); }; return ( @@ -145,6 +142,18 @@ const MemoDetail = () => { )} + {showCommentEditor && ( +
+ setShowCommentEditor(false)} + /> +
+ )} {md && (