chore: allow quick unpin (#4031)

Signed-off-by: d0zingcat <leewtang@gmail.com>
This commit is contained in:
d0zingcat 2024-10-19 16:05:14 +08:00 committed by GitHub
parent 19098940f7
commit 67dc9a3f0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,7 +5,7 @@ import { memo, useCallback, useEffect, useRef, useState } from "react";
import { Link, useLocation } from "react-router-dom";
import useCurrentUser from "@/hooks/useCurrentUser";
import useNavigateTo from "@/hooks/useNavigateTo";
import { useUserStore, useWorkspaceSettingStore } from "@/store/v1";
import { useUserStore, useWorkspaceSettingStore, useMemoStore } from "@/store/v1";
import { MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service";
import { Memo, Visibility } from "@/types/proto/api/v1/memo_service";
import { WorkspaceMemoRelatedSetting } from "@/types/proto/api/v1/workspace_setting_service";
@ -57,6 +57,7 @@ const MemoView: React.FC<Props> = (props: Props) => {
const relativeTimeFormat = Date.now() - memo.displayTime!.getTime() > 1000 * 60 * 60 * 24 ? "datetime" : "auto";
const readonly = memo.creator !== user?.name && !isSuperUser(user);
const isInMemoDetailPage = location.pathname.startsWith(`/m/${memo.uid}`);
const memoStore = useMemoStore();
// Initial related data: creator.
useEffect(() => {
@ -92,6 +93,22 @@ const MemoView: React.FC<Props> = (props: Props) => {
}
}, []);
const handlePinnedBookmarkClick = async () => {
try {
if (memo.pinned) {
await memoStore.updateMemo(
{
name: memo.name,
pinned: false,
},
["pinned"],
);
}
} catch (error) {
// do nth
}
};
const displayTime =
props.displayTimeFormat === "time" ? (
memo.displayTime?.toLocaleTimeString()
@ -176,8 +193,10 @@ const MemoView: React.FC<Props> = (props: Props) => {
</Link>
)}
{props.showPinned && memo.pinned && (
<Tooltip title={t("common.pinned")} placement="top">
<BookmarkIcon className="w-4 h-auto text-amber-500" />
<Tooltip title={t("common.unpin")} placement="top">
<span className="cursor-pointer">
<BookmarkIcon className="w-4 h-auto text-amber-500" onClick={handlePinnedBookmarkClick} />
</span>
</Tooltip>
)}
{!readonly && (