From 620ca67caa88b9dd20eb1326fba47ad0cbc805bc Mon Sep 17 00:00:00 2001 From: pfqgauxfb <3521106529@qq.com> Date: Mon, 2 Jun 2025 22:32:21 +0800 Subject: [PATCH] feng --- src/components/Comments/index.js | 37 ++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/components/Comments/index.js b/src/components/Comments/index.js index fce6a87..5e82265 100644 --- a/src/components/Comments/index.js +++ b/src/components/Comments/index.js @@ -1,7 +1,9 @@ import React, { useState } from 'react'; +import { useDoc } from '@docusaurus/theme-common/internal'; import styles from './styles.module.css'; const Comments = () => { + const doc = useDoc(); const [rating, setRating] = useState(0); const [comment, setComment] = useState(''); const [comments, setComments] = useState([]); @@ -15,6 +17,7 @@ const Comments = () => { rating, text: comment, date: new Date().toLocaleString(), + docId: doc.id, }, ]); setComment(''); @@ -56,24 +59,26 @@ const Comments = () => {
- {comments.map((item, index) => ( -
-
-
- {[1, 2, 3, 4, 5].map((star) => ( - - ★ - - ))} + {comments + .filter((item) => item.docId === doc.id) + .map((item, index) => ( +
+
+
+ {[1, 2, 3, 4, 5].map((star) => ( + + ★ + + ))} +
+ {item.date}
- {item.date} +

{item.text}

-

{item.text}

-
- ))} + ))}
);