mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: add memo actions to memo detail page
This commit is contained in:
@ -12,11 +12,13 @@ import showShareMemoDialog from "./ShareMemoDialog";
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
memo: Memo;
|
memo: Memo;
|
||||||
showPinned?: boolean;
|
hiddenActions?: ("edit" | "archive" | "delete" | "share" | "pin")[];
|
||||||
|
onArchived?: () => void;
|
||||||
|
onDeleted?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MemoActionMenu = (props: Props) => {
|
const MemoActionMenu = (props: Props) => {
|
||||||
const { memo, showPinned } = props;
|
const { memo, hiddenActions } = props;
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
const memoStore = useMemoStore();
|
const memoStore = useMemoStore();
|
||||||
|
|
||||||
@ -64,6 +66,9 @@ const MemoActionMenu = (props: Props) => {
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
toast.error(error.response.data.message);
|
toast.error(error.response.data.message);
|
||||||
}
|
}
|
||||||
|
if (props.onArchived) {
|
||||||
|
props.onArchived();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteMemoClick = async () => {
|
const handleDeleteMemoClick = async () => {
|
||||||
@ -74,6 +79,9 @@ const MemoActionMenu = (props: Props) => {
|
|||||||
dialogName: "delete-memo-dialog",
|
dialogName: "delete-memo-dialog",
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
await memoStore.deleteMemo(memo.id);
|
await memoStore.deleteMemo(memo.id);
|
||||||
|
if (props.onDeleted) {
|
||||||
|
props.onDeleted();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -91,20 +99,24 @@ const MemoActionMenu = (props: Props) => {
|
|||||||
</span>
|
</span>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<Menu className="text-sm" size="sm" placement="bottom-end">
|
<Menu className="text-sm" size="sm" placement="bottom-end">
|
||||||
{showPinned && (
|
{!hiddenActions?.includes("pin") && (
|
||||||
<MenuItem onClick={handleTogglePinMemoBtnClick}>
|
<MenuItem onClick={handleTogglePinMemoBtnClick}>
|
||||||
{memo.pinned ? <Icon.BookmarkMinus className="w-4 h-auto" /> : <Icon.BookmarkPlus className="w-4 h-auto" />}
|
{memo.pinned ? <Icon.BookmarkMinus className="w-4 h-auto" /> : <Icon.BookmarkPlus className="w-4 h-auto" />}
|
||||||
{memo.pinned ? t("common.unpin") : t("common.pin")}
|
{memo.pinned ? t("common.unpin") : t("common.pin")}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
)}
|
)}
|
||||||
<MenuItem onClick={handleEditMemoClick}>
|
{!hiddenActions?.includes("edit") && (
|
||||||
<Icon.Edit3 className="w-4 h-auto" />
|
<MenuItem onClick={handleEditMemoClick}>
|
||||||
{t("common.edit")}
|
<Icon.Edit3 className="w-4 h-auto" />
|
||||||
</MenuItem>
|
{t("common.edit")}
|
||||||
<MenuItem onClick={() => showShareMemoDialog(memo.id)}>
|
</MenuItem>
|
||||||
<Icon.Share className="w-4 h-auto" />
|
)}
|
||||||
{t("common.share")}
|
{!hiddenActions?.includes("share") && (
|
||||||
</MenuItem>
|
<MenuItem onClick={() => showShareMemoDialog(memo.id)}>
|
||||||
|
<Icon.Share className="w-4 h-auto" />
|
||||||
|
{t("common.share")}
|
||||||
|
</MenuItem>
|
||||||
|
)}
|
||||||
<Divider className="!my-1" />
|
<Divider className="!my-1" />
|
||||||
<MenuItem color="warning" onClick={handleArchiveMemoClick}>
|
<MenuItem color="warning" onClick={handleArchiveMemoClick}>
|
||||||
<Icon.Archive className="w-4 h-auto" />
|
<Icon.Archive className="w-4 h-auto" />
|
||||||
|
@ -135,7 +135,7 @@ const MemoView: React.FC<Props> = (props: Props) => {
|
|||||||
)}
|
)}
|
||||||
{currentUser && <ReactionSelector className="border-none" memo={memo} />}
|
{currentUser && <ReactionSelector className="border-none" memo={memo} />}
|
||||||
</div>
|
</div>
|
||||||
{!readonly && <MemoActionMenu memo={memo} showPinned={props.showPinned} />}
|
{!readonly && <MemoActionMenu memo={memo} hiddenActions={props.showPinned ? [] : ["pin"]} />}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<MemoContent
|
<MemoContent
|
||||||
|
@ -5,6 +5,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { toast } from "react-hot-toast";
|
import { toast } from "react-hot-toast";
|
||||||
import { Link, useParams } from "react-router-dom";
|
import { Link, useParams } from "react-router-dom";
|
||||||
import Icon from "@/components/Icon";
|
import Icon from "@/components/Icon";
|
||||||
|
import MemoActionMenu from "@/components/MemoActionMenu";
|
||||||
import MemoContent from "@/components/MemoContent";
|
import MemoContent from "@/components/MemoContent";
|
||||||
import MemoEditor from "@/components/MemoEditor";
|
import MemoEditor from "@/components/MemoEditor";
|
||||||
import showMemoEditorDialog from "@/components/MemoEditor/MemoEditorDialog";
|
import showMemoEditorDialog from "@/components/MemoEditor/MemoEditorDialog";
|
||||||
@ -113,6 +114,16 @@ const MemoDetail = () => {
|
|||||||
await memoStore.getOrFetchMemoById(memo.id, { skipCache: true });
|
await memoStore.getOrFetchMemoById(memo.id, { skipCache: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleMemoArchived = () => {
|
||||||
|
navigateTo("/archived");
|
||||||
|
toast.success("Memo archived");
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMemoDeleted = () => {
|
||||||
|
navigateTo("/");
|
||||||
|
toast.success("Memo deleted");
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="@container w-full max-w-5xl min-h-full flex flex-col justify-start items-center sm:pt-3 md:pt-6 pb-8">
|
<section className="@container w-full max-w-5xl min-h-full flex flex-col justify-start items-center sm:pt-3 md:pt-6 pb-8">
|
||||||
<MobileHeader />
|
<MobileHeader />
|
||||||
@ -184,6 +195,14 @@ const MemoDetail = () => {
|
|||||||
<Icon.Share className="w-4 h-auto text-gray-600 dark:text-gray-400" />
|
<Icon.Share className="w-4 h-auto text-gray-600 dark:text-gray-400" />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
{!readonly && (
|
||||||
|
<MemoActionMenu
|
||||||
|
memo={memo}
|
||||||
|
hiddenActions={["pin", "share"]}
|
||||||
|
onArchived={handleMemoArchived}
|
||||||
|
onDeleted={handleMemoDeleted}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user