import { create } from "@bufbuild/protobuf"; import { timestampDate } from "@bufbuild/protobuf/wkt"; import { isEqual } from "lodash-es"; import { CheckCircleIcon, Code2Icon, HashIcon, LinkIcon, type LucideIcon, Share2Icon } from "lucide-react"; import { useMemo, useState } from "react"; import { Button } from "@/components/ui/button"; import useCurrentUser from "@/hooks/useCurrentUser"; import { cn } from "@/lib/utils"; import { Memo, Memo_PropertySchema } from "@/types/proto/api/v1/memo_service_pb"; import { type Translations, useTranslate } from "@/utils/i18n"; import { extractHeadings } from "@/utils/markdown-manipulation"; import { isSuperUser } from "@/utils/user"; import MemoOutline from "./MemoOutline"; import MemoSharePanel from "./MemoSharePanel"; interface Props { memo: Memo; className?: string; } interface PropertyBadge { icon: LucideIcon; labelKey: Translations; } const SidebarSection = ({ label, count, children }: { label: string; count?: number; children: React.ReactNode }) => (

{label}

{count != null && ({count})}
{children}
); const PROPERTY_BADGE_CLASSES = "inline-flex items-center gap-1.5 px-2 py-1 rounded-md border border-border/60 bg-muted/60 text-xs text-muted-foreground"; const TAG_BADGE_CLASSES = "inline-flex items-center gap-1 px-1 rounded-md border border-border/60 bg-muted/60 text-sm text-muted-foreground hover:bg-muted hover:text-foreground/80 transition-colors cursor-pointer"; const MemoDetailSidebar = ({ memo, className }: Props) => { const t = useTranslate(); const currentUser = useCurrentUser(); const [sharePanelOpen, setSharePanelOpen] = useState(false); const property = create(Memo_PropertySchema, memo.property || {}); const canManageShares = !memo.parent && (memo.creator === currentUser?.name || isSuperUser(currentUser)); const hasUpdated = !isEqual(memo.createTime, memo.updateTime); const headings = useMemo(() => extractHeadings(memo.content), [memo.content]); const propertyBadges = useMemo(() => { const badges: PropertyBadge[] = []; if (property.hasLink) badges.push({ icon: LinkIcon, labelKey: "memo.links" }); if (property.hasTaskList) badges.push({ icon: CheckCircleIcon, labelKey: "memo.to-do" }); if (property.hasCode) badges.push({ icon: Code2Icon, labelKey: "memo.code" }); return badges; }, [property.hasLink, property.hasTaskList, property.hasCode]); return ( ); }; export default MemoDetailSidebar;