diff --git a/web/src/components/Inbox/MemoCommentMessage.tsx b/web/src/components/Inbox/MemoCommentMessage.tsx index 85097de0..bfc70767 100644 --- a/web/src/components/Inbox/MemoCommentMessage.tsx +++ b/web/src/components/Inbox/MemoCommentMessage.tsx @@ -1,9 +1,10 @@ import { Tooltip } from "@mui/joy"; import clsx from "clsx"; -import { InboxIcon, MessageCircleIcon } from "lucide-react"; -import { useEffect, useState } from "react"; +import { InboxIcon, LoaderIcon, MessageCircleIcon } from "lucide-react"; +import { useState } from "react"; import toast from "react-hot-toast"; import { activityServiceClient } from "@/grpcweb"; +import useAsyncEffect from "@/hooks/useAsyncEffect"; import useNavigateTo from "@/hooks/useNavigateTo"; import { activityNamePrefix, memoNamePrefix, useInboxStore, useMemoStore, useUserStore } from "@/store/v1"; import { Inbox, Inbox_Status } from "@/types/proto/api/v1/inbox_service"; @@ -23,27 +24,27 @@ const MemoCommentMessage = ({ inbox }: Props) => { const userStore = useUserStore(); const [relatedMemo, setRelatedMemo] = useState(undefined); const [sender, setSender] = useState(undefined); + const [initialized, setInitialized] = useState(false); - useEffect(() => { + useAsyncEffect(async () => { if (!inbox.activityId) { return; } - (async () => { - const activity = await activityServiceClient.getActivity({ - name: `${activityNamePrefix}${inbox.activityId}`, + const activity = await activityServiceClient.getActivity({ + name: `${activityNamePrefix}${inbox.activityId}`, + }); + if (activity.payload?.memoComment) { + const memoCommentPayload = activity.payload.memoComment; + const relatedMemoId = memoCommentPayload.relatedMemoId; + const memo = await memoStore.getOrFetchMemoByName(`${memoNamePrefix}${relatedMemoId}`, { + skipStore: true, }); - if (activity.payload?.memoComment) { - const memoCommentPayload = activity.payload.memoComment; - const relatedMemoId = memoCommentPayload.relatedMemoId; - const memo = await memoStore.getOrFetchMemoByName(`${memoNamePrefix}${relatedMemoId}`, { - skipStore: true, - }); - setRelatedMemo(memo); - const sender = await userStore.getOrFetchUserByName(inbox.sender); - setSender(sender); - } - })(); + setRelatedMemo(memo); + const sender = await userStore.getOrFetchUserByName(inbox.sender); + setSender(sender); + setInitialized(true); + } }, [inbox.activityId]); const handleNavigateToMemo = async () => { @@ -86,30 +87,41 @@ const MemoCommentMessage = ({ inbox }: Props) => {
-
- {inbox.createTime?.toLocaleString()} -
- {inbox.status === Inbox_Status.UNREAD && ( - - handleArchiveMessage()} /> - - )} + {initialized ? ( + <> +
+ {inbox.createTime?.toLocaleString()} +
+ {inbox.status === Inbox_Status.UNREAD && ( + + handleArchiveMessage()} + /> + + )} +
+
+

+ {t("inbox.memo-comment", { + user: sender?.nickname || sender?.username, + memo: `memos/${relatedMemo?.uid}`, + interpolation: { escapeValue: false }, + })} +

+ + ) : ( +
+
-
-

- {t("inbox.memo-comment", { - user: sender?.nickname || sender?.username, - memo: `memos/${relatedMemo?.uid}`, - interpolation: { escapeValue: false }, - })} -

+ )}
); diff --git a/web/src/components/Inbox/VersionUpdateMessage.tsx b/web/src/components/Inbox/VersionUpdateMessage.tsx index 62b8781c..2656a1a7 100644 --- a/web/src/components/Inbox/VersionUpdateMessage.tsx +++ b/web/src/components/Inbox/VersionUpdateMessage.tsx @@ -71,12 +71,12 @@ const VersionUpdateMessage = ({ inbox }: Props) => {
- {inbox.createTime?.toLocaleString()} + {inbox.createTime?.toLocaleString()}
{inbox.status === Inbox_Status.UNREAD && (