diff --git a/frontend/src/App.js b/frontend/src/App.js index cacbc41..41be71a 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -1,6 +1,12 @@ import React from 'react'; import { Routes, Route } from 'react-router-dom'; +import { observer } from 'mobx-react-lite'; import styled from 'styled-components'; +import { useAuthStore } from './stores/AuthStore'; +import Layout from './components/common/Layout'; +import Loading from './components/common/Loading'; +import CitiesPage from './components/region/CitiesPage'; +import CityDetailPage from './components/region/CityDetailPage'; const Container = styled.div` max-width: 1200px; @@ -20,16 +26,100 @@ const Title = styled.h1` `; function App() { + const authStore = useAuthStore(); + + // Fetch current user on app load + React.useEffect(() => { + if (authStore.isAuthenticated) { + authStore.fetchCurrentUser(); + } + }, [authStore]); + return ( - -
- React + Django App -
+ - Welcome to the app!} /> + } /> + } /> + } /> + } /> + } /> -
+ ); } +const HomePage = observer(() => { + return ( + +
+ 欢迎来到城市手册 +

探索每个城市的故事与特色

+
+
+

热门城市

+

即将推出...

+
+
+

最新文章

+

即将推出...

+
+
+ ); +}); + +const UserProfilePage = observer(() => { + const authStore = useAuthStore(); + const userStore = useUserStore(); + + React.useEffect(() => { + if (authStore.isAuthenticated) { + userStore.fetchCurrentUser(); + } + }, [authStore, userStore]); + + if (!authStore.isAuthenticated) { + return ( + +

请先登录

+
+ ); + } + + if (userStore.loading) { + return ; + } + + return ( + +
+ 个人中心 +
+ {userStore.user && ( +
+

用户信息

+

用户名: {userStore.user.username}

+

邮箱: {userStore.user.email}

+

角色: {userStore.user.role_display}

+ +

统计

+

文章数: {userStore.user.articles_count}

+

服务数: {userStore.user.services_count}

+

评论数: {userStore.user.comments_count}

+

点赞数: {userStore.user.likes_count}

+

收藏数: {userStore.user.favorites_count}

+
+ )} +
+ ); +}); + +const NotFoundPage = () => ( + +
+ 404 +
+

页面未找到

+
+); + export default App; \ No newline at end of file