From fbbfb1191602652fef399f87df0ad794b3891a45 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 28 Sep 2023 08:59:55 +0800 Subject: [PATCH] chore: adjust memo elements --- web/src/components/Memo.tsx | 62 +++++++++++++--- .../Settings/PreferencesSection.tsx | 2 +- web/src/helpers/consts.ts | 6 +- web/src/pages/MemoDetail.tsx | 72 ++++++++++--------- 4 files changed, 92 insertions(+), 50 deletions(-) diff --git a/web/src/components/Memo.tsx b/web/src/components/Memo.tsx index 965b2938..028d32cd 100644 --- a/web/src/components/Memo.tsx +++ b/web/src/components/Memo.tsx @@ -1,9 +1,9 @@ -import { Divider } from "@mui/joy"; +import { Divider, Select, Tooltip, Option } from "@mui/joy"; import { memo, useEffect, useRef, useState } from "react"; import { toast } from "react-hot-toast"; import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; -import { UNKNOWN_ID } from "@/helpers/consts"; +import { UNKNOWN_ID, VISIBILITY_SELECTOR_ITEMS } from "@/helpers/consts"; import { getRelativeTimeString } from "@/helpers/datetime"; import useCurrentUser from "@/hooks/useCurrentUser"; import useNavigateTo from "@/hooks/useNavigateTo"; @@ -90,6 +90,14 @@ const Memo: React.FC = (props: Props) => { return
; } + const handleMemoVisibilityOptionChanged = async (value: string) => { + const visibilityValue = value as Visibility; + await memoStore.patchMemo({ + id: memo.id, + visibility: visibilityValue, + }); + }; + const handleGotoMemoDetailPage = (event: React.MouseEvent) => { if (event.altKey) { showChangeMemoCreatedTsDialog(memo.id); @@ -227,15 +235,6 @@ const Memo: React.FC = (props: Props) => {
- {creator && ( - <> - - - {creator.nickname} - - - - )} {displayTime} @@ -282,6 +281,47 @@ const Memo: React.FC = (props: Props) => { /> +
+
+ {creator && ( + <> + + + #{memo.id} + + + + + + {creator.nickname} + + {props.showVisibility && ( + <> + + + + + + )} + + )} +
+
); diff --git a/web/src/components/Settings/PreferencesSection.tsx b/web/src/components/Settings/PreferencesSection.tsx index d1e0db1b..8024dd35 100644 --- a/web/src/components/Settings/PreferencesSection.tsx +++ b/web/src/components/Settings/PreferencesSection.tsx @@ -19,7 +19,7 @@ const PreferencesSection = () => { const visibilitySelectorItems = VISIBILITY_SELECTOR_ITEMS.map((item) => { return { value: item.value, - text: t(`memo.visibility.${item.text.toLowerCase() as Lowercase}`), + text: t(`memo.visibility.${item.value.toLowerCase() as Lowercase}`), }; }); diff --git a/web/src/helpers/consts.ts b/web/src/helpers/consts.ts index 70ef8574..16229ea0 100644 --- a/web/src/helpers/consts.ts +++ b/web/src/helpers/consts.ts @@ -9,9 +9,9 @@ export const ANIMATION_DURATION = 200; export const DAILY_TIMESTAMP = 3600 * 24 * 1000; export const VISIBILITY_SELECTOR_ITEMS = [ - { text: "PRIVATE", value: "PRIVATE" }, - { text: "PROTECTED", value: "PROTECTED" }, - { text: "PUBLIC", value: "PUBLIC" }, + { text: "Private", value: "PRIVATE" }, + { text: "Workspace", value: "PROTECTED" }, + { text: "Public", value: "PUBLIC" }, ] as const; // space width for tab action in editor diff --git a/web/src/pages/MemoDetail.tsx b/web/src/pages/MemoDetail.tsx index 2c1d9d4e..8cfa35f7 100644 --- a/web/src/pages/MemoDetail.tsx +++ b/web/src/pages/MemoDetail.tsx @@ -1,9 +1,8 @@ import { Divider, Select, Tooltip, Option, IconButton } from "@mui/joy"; import copy from "copy-to-clipboard"; -import { toLower } from "lodash-es"; import { useEffect, useState } from "react"; import { toast } from "react-hot-toast"; -import { useParams } from "react-router-dom"; +import { Link, useParams } from "react-router-dom"; import FloatingNavButton from "@/components/FloatingNavButton"; import Icon from "@/components/Icon"; import MemoContent from "@/components/MemoContent"; @@ -16,7 +15,7 @@ import { VISIBILITY_SELECTOR_ITEMS } from "@/helpers/consts"; import { getDateTimeString } from "@/helpers/datetime"; import useCurrentUser from "@/hooks/useCurrentUser"; import useNavigateTo from "@/hooks/useNavigateTo"; -import { useMemoStore } from "@/store/module"; +import { useGlobalStore, useMemoStore } from "@/store/module"; import { useUserV1Store } from "@/store/v1"; import { User } from "@/types/proto/api/v2/user_service"; import { useTranslate } from "@/utils/i18n"; @@ -25,10 +24,12 @@ const MemoDetail = () => { const params = useParams(); const navigateTo = useNavigateTo(); const t = useTranslate(); + const globalStore = useGlobalStore(); const memoStore = useMemoStore(); const userV1Store = useUserV1Store(); const currentUser = useCurrentUser(); const [user, setUser] = useState(); + const { systemStatus } = globalStore.state; const memoId = Number(params.memoId); const memo = memoStore.state.memos.find((memo) => memo.id === memoId); const allowEdit = memo?.creatorUsername === currentUser?.username; @@ -54,13 +55,6 @@ const MemoDetail = () => { return null; } - const memoVisibilityOptionSelectorItems = VISIBILITY_SELECTOR_ITEMS.map((item) => { - return { - value: item.value, - text: t(`memo.visibility.${toLower(item.value) as Lowercase}`), - }; - }); - const handleMemoVisibilityOptionChanged = async (value: string) => { const visibilityValue = value as Visibility; await memoStore.patchMemo({ @@ -85,42 +79,50 @@ const MemoDetail = () => {
- -
-

{user?.nickname}

-
+ +

{systemStatus.customizedProfile.name}

+
+ {getDateTimeString(memo.displayTs)} +
- {getDateTimeString(memo.displayTs)} - · #{memo.id} - · - - - + + + + {user?.nickname} + + {allowEdit && ( + <> + + + + + + )}
{allowEdit && (