From e7a788fa7119be0390413736b178296d85c580ac Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 9 May 2024 20:10:13 +0800 Subject: [PATCH] chore: tweak memo detail page --- .../MemoEditor/MemoEditorDialog.tsx | 32 ++++++++---- web/src/components/MemoEditor/index.tsx | 2 +- web/src/less/base-dialog.less | 2 +- web/src/locales/en.json | 4 +- web/src/pages/MemoDetail.tsx | 51 +++++++++++-------- 5 files changed, 57 insertions(+), 34 deletions(-) diff --git a/web/src/components/MemoEditor/MemoEditorDialog.tsx b/web/src/components/MemoEditor/MemoEditorDialog.tsx index 091592a4..ad2dd23a 100644 --- a/web/src/components/MemoEditor/MemoEditorDialog.tsx +++ b/web/src/components/MemoEditor/MemoEditorDialog.tsx @@ -1,18 +1,21 @@ import { IconButton } from "@mui/joy"; import { useEffect } from "react"; import { useTagStore } from "@/store/v1"; -import { MemoRelation } from "@/types/proto/api/v1/memo_relation_service"; -import MemoEditor from "."; +import MemoEditor, { Props as MemoEditorProps } from "."; import { generateDialog } from "../Dialog"; import Icon from "../Icon"; -interface Props extends DialogProps { - memoName?: string; - cacheKey?: string; - relationList?: MemoRelation[]; -} +interface Props extends DialogProps, MemoEditorProps {} -const MemoEditorDialog: React.FC = ({ memoName: memo, cacheKey, relationList, destroy }: Props) => { +const MemoEditorDialog: React.FC = ({ + memoName: memo, + parentMemoName, + placeholder, + cacheKey, + relationList, + onConfirm, + destroy, +}: Props) => { const tagStore = useTagStore(); useEffect(() => { @@ -23,6 +26,13 @@ const MemoEditorDialog: React.FC = ({ memoName: memo, cacheKey, relationL destroy(); }; + const handleConfirm = (memoName: string) => { + handleCloseBtnClick(); + if (onConfirm) { + onConfirm(memoName); + } + }; + return ( <>
@@ -39,8 +49,10 @@ const MemoEditorDialog: React.FC = ({ memoName: memo, cacheKey, relationL className="border-none !p-0 -mb-2" cacheKey={`memo-editor-${cacheKey || memo}`} memoName={memo} + parentMemoName={parentMemoName} + placeholder={placeholder} relationList={relationList} - onConfirm={handleCloseBtnClick} + onConfirm={handleConfirm} autoFocus />
@@ -48,7 +60,7 @@ const MemoEditorDialog: React.FC = ({ memoName: memo, cacheKey, relationL ); }; -export default function showMemoEditorDialog(props: Pick = {}): void { +export default function showMemoEditorDialog(props: Partial = {}): void { generateDialog( { className: "memo-editor-dialog", diff --git a/web/src/components/MemoEditor/index.tsx b/web/src/components/MemoEditor/index.tsx index e5079432..68b4e676 100644 --- a/web/src/components/MemoEditor/index.tsx +++ b/web/src/components/MemoEditor/index.tsx @@ -28,7 +28,7 @@ import ResourceListView from "./ResourceListView"; import { handleEditorKeydownWithMarkdownShortcuts, hyperlinkHighlightedText } from "./handlers"; import { MemoEditorContext } from "./types"; -interface Props { +export interface Props { className?: string; cacheKey?: string; placeholder?: string; diff --git a/web/src/less/base-dialog.less b/web/src/less/base-dialog.less index b6777709..e40e2080 100644 --- a/web/src/less/base-dialog.less +++ b/web/src/less/base-dialog.less @@ -1,5 +1,5 @@ .dialog-wrapper { - @apply fixed top-0 left-0 flex flex-col justify-start items-center w-full h-full pt-16 pb-8 px-4 z-2000 overflow-x-hidden overflow-y-scroll bg-transparent transition-all hide-scrollbar bg-black bg-opacity-60; + @apply fixed top-0 left-0 flex flex-col justify-start items-center w-full h-full pt-16 pb-8 px-4 z-1000 overflow-x-hidden overflow-y-scroll bg-transparent transition-all hide-scrollbar bg-black bg-opacity-60; > .dialog-container { @apply max-w-full shadow flex flex-col justify-start items-start bg-white dark:bg-zinc-800 dark:text-gray-300 p-4 rounded-lg; diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 323a630e..6f257dad 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -96,8 +96,8 @@ "memo": { "archived-at": "Archived at", "comment": { - "no-comment": "No comment", - "self": "Comments" + "self": "Comments", + "write-a-comment": "Write a comment" }, "copy-link": "Copy Link", "count-memos-in-date": "{{count}} memos in {{date}}", diff --git a/web/src/pages/MemoDetail.tsx b/web/src/pages/MemoDetail.tsx index 8155c877..799aa253 100644 --- a/web/src/pages/MemoDetail.tsx +++ b/web/src/pages/MemoDetail.tsx @@ -1,9 +1,10 @@ +import { Button } from "@mui/joy"; import { ClientError } from "nice-grpc-web"; import { useEffect, useState } from "react"; import { toast } from "react-hot-toast"; import { Link, useParams } from "react-router-dom"; import Icon from "@/components/Icon"; -import MemoEditor from "@/components/MemoEditor"; +import showMemoEditorDialog from "@/components/MemoEditor/MemoEditorDialog"; import MemoView from "@/components/MemoView"; import MobileHeader from "@/components/MobileHeader"; import useCurrentUser from "@/hooks/useCurrentUser"; @@ -60,6 +61,14 @@ const MemoDetail = () => { return null; } + const handleShowCommentEditor = () => { + showMemoEditorDialog({ + placeholder: t("editor.add-your-comment-here"), + parentMemoName: memo.name, + onConfirm: handleCommentCreated, + }); + }; + const handleCommentCreated = async (memoCommentName: string) => { await memoStore.getOrFetchMemoByName(memoCommentName); await memoStore.getOrFetchMemoByName(memo.name, { skipCache: true }); @@ -96,33 +105,35 @@ const MemoDetail = () => {
{comments.length === 0 ? ( -
- -

{t("memo.comment.no-comment")}

-
+ currentUser && ( +
+ +
+ ) ) : ( <> -
- - {t("memo.comment.self")} - ({comments.length}) +
+
+ + {t("memo.comment.self")} + ({comments.length}) +
+
{comments.map((comment) => ( ))} )} - - {/* Only show comment editor when user login */} - {currentUser && ( - - )}