新增路由管理
Change-Id: I8139fd09f135c42944f60ca473ee208e69549dc2
diff --git a/Merge/front/src/components/NotebookPage.jsx b/Merge/front/src/components/NotebookPage.jsx
index 25264ec..4214213 100644
--- a/Merge/front/src/components/NotebookPage.jsx
+++ b/Merge/front/src/components/NotebookPage.jsx
@@ -3,6 +3,7 @@
import React, { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom'
import { fetchPosts, deletePost } from '../api/posts_wzy'
+import { getUserInfo } from '../utils/auth' // ← 导入 getUserInfo
import '../style/NotebookPage.css'
export default function NotebookPage() {
@@ -11,13 +12,20 @@
const [loading, setLoading] = useState(true)
const [error, setError] = useState(null)
- // TODO: 替换成真实用户 ID
- const currentUserId = 2
+ // 从 auth 获取当前用户信息
+ const userInfo = getUserInfo()
+ const currentUserId = userInfo?.id
useEffect(() => {
+ if (!currentUserId) {
+ setError('未获取到用户信息,无法加载帖子。')
+ setLoading(false)
+ return
+ }
+
async function load() {
try {
- // GET /posts?user_id=1
+ // GET /posts?user_id=currentUserId
const list = await fetchPosts(currentUserId)
setPosts(list)
} catch (e) {
@@ -27,7 +35,7 @@
}
}
load()
- }, [])
+ }, [currentUserId])
async function handleDelete(id) {
if (!window.confirm('确定要删除该帖子吗?')) return
@@ -41,7 +49,6 @@
}
function handleEdit(id) {
- // 假设你在路由里挂载了 /posts/edit/:postId
navigate(`/posts/edit/${id}`)
}