diff --git a/src/components/Comments/index.js b/src/components/Comments/index.js deleted file mode 100644 index 4b9aa9e..0000000 --- a/src/components/Comments/index.js +++ /dev/null @@ -1,109 +0,0 @@ -import React, { useState, useEffect } from 'react'; -import styles from './styles.module.css'; - -const Comments = () => { - const [comments, setComments] = useState([]); - const [newComment, setNewComment] = useState(''); - const [name, setName] = useState(''); - const [mounted, setMounted] = useState(false); - - useEffect(() => { - setMounted(true); - const savedComments = localStorage.getItem('docComments'); - if (savedComments) { - try { - setComments(JSON.parse(savedComments)); - } catch (e) { - console.error('Failed to parse comments:', e); - } - } - }, []); - - const saveComments = (newComments) => { - try { - localStorage.setItem('docComments', JSON.stringify(newComments)); - } catch (e) { - console.error('Failed to save comments:', e); - } - }; - - const handleSubmit = (e) => { - e.preventDefault(); - if (!newComment.trim() || !name.trim()) return; - - const comment = { - id: Date.now(), - name, - content: newComment, - date: new Date().toLocaleString(), - }; - - const updatedComments = [...comments, comment]; - setComments(updatedComments); - saveComments(updatedComments); - setNewComment(''); - }; - - const handleDelete = (commentId) => { - const updatedComments = comments.filter(comment => comment.id !== commentId); - setComments(updatedComments); - saveComments(updatedComments); - }; - - if (!mounted) { - return null; - } - - return ( -
-

评论

- -
-
- setName(e.target.value)} - placeholder="您的名字" - className={styles.input} - required - /> -
-
-