diff --git a/web/src/components/MemoMetadata/Relation/LinkMemoDialog.tsx b/web/src/components/MemoMetadata/Relation/LinkMemoDialog.tsx index cbef9c9b4..7721e842f 100644 --- a/web/src/components/MemoMetadata/Relation/LinkMemoDialog.tsx +++ b/web/src/components/MemoMetadata/Relation/LinkMemoDialog.tsx @@ -4,7 +4,6 @@ import { MemoPreview } from "@/components/MemoPreview"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogTitle } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { VisuallyHidden } from "@/components/ui/visually-hidden"; -import { extractMemoIdFromName } from "@/helpers/resource-names"; import { cn } from "@/lib/utils"; import type { Memo } from "@/types/proto/api/v1/memo_service_pb"; import { useTranslate } from "@/utils/i18n"; @@ -75,12 +74,9 @@ export const LinkMemoDialog = ({
{alreadyLinked && } - - {extractMemoIdFromName(memo.name).slice(0, 6)} - {memo.displayTime && timestampDate(memo.displayTime).toLocaleString()}
- +
); diff --git a/web/src/components/MemoPreview/MemoPreview.tsx b/web/src/components/MemoPreview/MemoPreview.tsx index de858c6dd..91a059625 100644 --- a/web/src/components/MemoPreview/MemoPreview.tsx +++ b/web/src/components/MemoPreview/MemoPreview.tsx @@ -1,8 +1,10 @@ import { create } from "@bufbuild/protobuf"; import { FileIcon } from "lucide-react"; +import { extractMemoIdFromName } from "@/helpers/resource-names"; import { cn } from "@/lib/utils"; import type { Attachment } from "@/types/proto/api/v1/attachment_service_pb"; import { MemoSchema } from "@/types/proto/api/v1/memo_service_pb"; +import type { User } from "@/types/proto/api/v1/user_service_pb"; import { getAttachmentType, getAttachmentUrl } from "@/utils/attachment"; import MemoContent from "../MemoContent"; import { MemoViewContext, type MemoViewContextValue } from "../MemoView/MemoViewContext"; @@ -10,8 +12,13 @@ import { MemoViewContext, type MemoViewContextValue } from "../MemoView/MemoView interface MemoPreviewProps { content: string; attachments: Attachment[]; + name?: string; compact?: boolean; className?: string; + creator?: User; + showCreator?: boolean; + showMemoId?: boolean; + truncate?: boolean; } const STUB_CONTEXT: MemoViewContextValue = { @@ -57,18 +64,76 @@ const AttachmentThumbnails = ({ attachments }: { attachments: Attachment[] }) => ); }; -const MemoPreview = ({ content, attachments, compact = true, className }: MemoPreviewProps) => { +const PreviewMeta = ({ + creator, + showCreator, + memoName, + showMemoId, +}: { + creator?: User; + showCreator?: boolean; + memoName?: string; + showMemoId?: boolean; +}) => { + const creatorName = creator?.displayName || creator?.username; + const memoId = showMemoId && memoName ? extractMemoIdFromName(memoName).slice(0, 6) : undefined; + + if (!creatorName && !memoId) { + return null; + } + + return ( +
+ {showMemoId && memoId && ( + {memoId} + )} + {showCreator && creatorName && {creatorName}} +
+ ); +}; + +const MemoPreview = ({ + content, + attachments, + name, + compact = true, + className, + creator, + showCreator = false, + showMemoId = false, + truncate = false, +}: MemoPreviewProps) => { const hasContent = content.trim().length > 0; const hasAttachments = attachments.length > 0; + const showMeta = showCreator || showMemoId; if (!hasContent && !hasAttachments) { return null; } + const meta = ; + const contentNode = truncate ? ( + hasContent ? ( +
{content}
+ ) : hasAttachments ? null : ( +
No content
+ ) + ) : ( + hasContent && + ); + return ( -
- {hasContent && } +
+ {showMeta && meta} + {showMeta && truncate && hasContent &&
ยท
} + {contentNode} {hasAttachments && }
diff --git a/web/src/components/MemoView/components/MemoCommentListView.tsx b/web/src/components/MemoView/components/MemoCommentListView.tsx index 58957ce4a..c416449b5 100644 --- a/web/src/components/MemoView/components/MemoCommentListView.tsx +++ b/web/src/components/MemoView/components/MemoCommentListView.tsx @@ -1,9 +1,10 @@ import { ArrowUpRightIcon } from "lucide-react"; import { Link } from "react-router-dom"; +import { MemoPreview } from "@/components/MemoPreview"; import { extractMemoIdFromName } from "@/helpers/resource-names"; import { useMemoComments } from "@/hooks/useMemoQueries"; +import { useUsersByNames } from "@/hooks/useUserQueries"; import { useMemoViewContext, useMemoViewDerived } from "../MemoViewContext"; -import MemoSnippetLink from "./MemoSnippetLink"; const MemoCommentListView: React.FC = () => { const { memo } = useMemoViewContext(); @@ -11,13 +12,13 @@ const MemoCommentListView: React.FC = () => { const { data } = useMemoComments(memo.name, { enabled: !isInMemoDetailPage && commentAmount > 0 }); const comments = data?.memos ?? []; + const displayedComments = comments.slice(0, 3); + const { data: commentCreators } = useUsersByNames(displayedComments.map((comment) => comment.creator)); if (isInMemoDetailPage || commentAmount === 0) { return null; } - const displayedComments = comments.slice(0, 3); - return (
@@ -32,14 +33,22 @@ const MemoCommentListView: React.FC = () => {
{displayedComments.map((comment) => { const uid = extractMemoIdFromName(comment.name); + const creator = commentCreators?.get(comment.creator); return ( - + viewTransition + className="rounded-md bg-muted/40 px-2 py-1 transition-colors hover:bg-muted/60" + > + + ); })}