From 67dc9a3f0ae20ff1c298bd852ad5f0b485cc81dc Mon Sep 17 00:00:00 2001 From: d0zingcat Date: Sat, 19 Oct 2024 16:05:14 +0800 Subject: [PATCH] chore: allow quick unpin (#4031) Signed-off-by: d0zingcat --- web/src/components/MemoView.tsx | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/web/src/components/MemoView.tsx b/web/src/components/MemoView.tsx index e449f581..273da741 100644 --- a/web/src/components/MemoView.tsx +++ b/web/src/components/MemoView.tsx @@ -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) => { 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) => { } }, []); + 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.showPinned && memo.pinned && ( - - + + + + )} {!readonly && (