import { LoaderCircleIcon, MessageCircleIcon } from "lucide-react"; import { type ComponentType, useCallback, useState } from "react"; import { loadMemoEditor } from "@/components/MemoEditor/loader"; import type { MemoEditorProps } from "@/components/MemoEditor/types"; import MemoView from "@/components/MemoView"; import { Button } from "@/components/ui/button"; import useCurrentUser from "@/hooks/useCurrentUser"; import { extractMemoIdFromName } from "@/lib/resource-names"; import type { Memo } from "@/types/proto/api/v1/memo_service_pb"; import { useTranslate } from "@/utils/i18n"; interface Props { memo: Memo; comments: Memo[]; parentPage?: string; hasMoreComments?: boolean; isFetchingMoreComments?: boolean; onLoadMoreComments?: () => void; } const MemoCommentSection = ({ memo, comments, parentPage, hasMoreComments, isFetchingMoreComments, onLoadMoreComments }: Props) => { const t = useTranslate(); const currentUser = useCurrentUser(); const [showEditor, setShowEditor] = useState(false); const [isEditorLoading, setIsEditorLoading] = useState(false); const [EditorComponent, setEditorComponent] = useState>(); const showCreateButton = currentUser && !showEditor; const handleCommentCreated = async (_memoCommentName: string) => { setShowEditor(false); }; const preloadEditor = useCallback(() => { void loadMemoEditor().catch(() => undefined); }, []); const openEditor = useCallback(async () => { if (isEditorLoading) { return; } setIsEditorLoading(true); try { const { default: MemoEditor } = await loadMemoEditor(); setEditorComponent(() => MemoEditor); setShowEditor(true); } catch { // Chunk failures are handled by loadWithReload; keep the current UI mounted. } finally { setIsEditorLoading(false); } }, [isEditorLoading]); return (

{t("memo.comment.self")}

{comments.length === 0 ? ( showCreateButton && (
) ) : (
{t("memo.comment.self")} ({comments.length})
{showCreateButton && ( )}
)} {showEditor && EditorComponent && (
setShowEditor(false)} />
)} {comments.map((comment) => (
))} {hasMoreComments && (
)}
); }; export default MemoCommentSection;