diff --git a/web/src/components/Memo.tsx b/web/src/components/Memo.tsx index 303fe3fa..25c418ad 100644 --- a/web/src/components/Memo.tsx +++ b/web/src/components/Memo.tsx @@ -44,6 +44,10 @@ const Memo: React.FC = (props: Props) => { const memoContainerRef = useRef(null); const readonly = memo.creatorUsername !== user?.username; const creator = userV1Store.getUserByUsername(memo.creatorUsername); + const referenceRelations = memo.relationList.filter( + (relation) => relation.memoId === memo.id && relation.relatedMemoId !== memo.id && relation.type === "REFERENCE" + ); + const commentRelations = memo.relationList.filter((relation) => relation.relatedMemoId === memo.id && relation.type === "COMMENT"); // Prepare memo creator. useEffect(() => { @@ -89,7 +93,7 @@ const Memo: React.FC = (props: Props) => { if (!shouldRender) { // Render a placeholder to occupy the space. - return
; + return
; } const handleGotoMemoDetailPage = (event: React.MouseEvent) => { @@ -271,7 +275,7 @@ const Memo: React.FC = (props: Props) => { {memo.parent && props.showCommentEntry && (
- This is a comment of #{memo.parent.id} + This is a comment of #{memo.parent.id}
)} @@ -281,7 +285,7 @@ const Memo: React.FC = (props: Props) => { onMemoContentDoubleClick={handleMemoContentDoubleClick} /> - +
{creator && ( @@ -306,6 +310,11 @@ const Memo: React.FC = (props: Props) => { )} + + + + {commentRelations.length} + )}
diff --git a/web/src/components/MemoEditor/index.tsx b/web/src/components/MemoEditor/index.tsx index f4439376..4686b96d 100644 --- a/web/src/components/MemoEditor/index.tsx +++ b/web/src/components/MemoEditor/index.tsx @@ -61,6 +61,11 @@ const MemoEditor = (props: Props) => { const editorRef = useRef(null); const user = userStore.state.user as User; const setting = user.setting; + const referenceRelations = memoId + ? state.relationList.filter( + (relation) => relation.memoId === memoId && relation.relatedMemoId !== memoId && relation.type === "REFERENCE" + ) + : state.relationList.filter((relation) => relation.type === "REFERENCE"); useEffect(() => { editorRef.current?.setContent(contentCache || ""); @@ -406,7 +411,7 @@ const MemoEditor = (props: Props) => {
- +
diff --git a/web/src/components/MemoRelationListView.tsx b/web/src/components/MemoRelationListView.tsx index 7b7684a2..dc660264 100644 --- a/web/src/components/MemoRelationListView.tsx +++ b/web/src/components/MemoRelationListView.tsx @@ -12,9 +12,7 @@ const MemoRelationListView = (props: Props) => { useEffect(() => { (async () => { - // Only show reference relations. - const relationList = props.relationList.filter((relation) => relation.type === "REFERENCE"); - const memoList = await Promise.all(relationList.map((relation) => memoCacheStore.getOrFetchMemoById(relation.relatedMemoId))); + const memoList = await Promise.all(props.relationList.map((relation) => memoCacheStore.getOrFetchMemoById(relation.relatedMemoId))); setRelatedMemoList(memoList); })(); }, [props.relationList]); diff --git a/web/src/pages/MemoDetail.tsx b/web/src/pages/MemoDetail.tsx index fe5ef0a2..6891e358 100644 --- a/web/src/pages/MemoDetail.tsx +++ b/web/src/pages/MemoDetail.tsx @@ -38,6 +38,10 @@ const MemoDetail = () => { const memoId = Number(params.memoId); const memo = memoStore.state.memos.find((memo) => memo.id === memoId); const allowEdit = memo?.creatorUsername === currentUser?.username; + const referenceRelations = + memo?.relationList.filter( + (relation) => relation.memoId === memo?.id && relation.relatedMemoId !== memo?.id && relation.type === "REFERENCE" + ) || []; // Prepare memo. useEffect(() => { @@ -114,9 +118,16 @@ const MemoDetail = () => {
{getDateTimeString(memo.displayTs)}
+ {memo.parent && ( +
+ + This is a comment of #{memo.parent.id} + +
+ )} - +
@@ -174,15 +185,24 @@ const MemoDetail = () => {
- {comments.map((comment) => ( - - ))} - {comments.length === 0 && ( + {comments.length === 0 ? (

No comments

+ ) : ( + <> +
+ + Comments + ({comments.length}) +
+ {comments.map((comment) => ( + + ))} + )} + {/* Only show comment editor when user login */} {currentUser && ( <>