diff --git a/web/src/App.tsx b/web/src/App.tsx index 474361d0..8595f267 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,26 +1,35 @@ import { useRoutes } from "react-router"; -import Navbar from "@/components/navigations/Navbar"; +import Navbar, { + NavItems, + AdminNavItems, +} from "@/components/navigations/Navbar"; import routes from "~react-pages"; -import { Box, LoadingOverlay, MantineProvider } from "@mantine/core"; -import { emotionTransform, MantineEmotionProvider } from "@mantine/emotion"; -import { Suspense, useEffect } from "react"; -import { useTheme } from "@/utils/theme"; +import { + AppShell, + Button, + LoadingOverlay, + UnstyledButton, +} from "@mantine/core"; +import { Suspense, useEffect, useState } from "react"; import { useCategoryApi } from "@/api/category"; import { useCategoryStore } from "@/stores/category"; import { useConfigApi } from "@/api/config"; import { useConfigStore } from "@/stores/config"; -import { Notifications } from "@mantine/notifications"; -import { ModalsProvider } from "@mantine/modals"; -import { DatesProvider } from "@mantine/dates"; import "dayjs/locale/zh-cn"; +import { useDisclosure } from "@mantine/hooks"; +import { Link, useLocation } from "react-router-dom"; +import MDIcon from "./components/ui/MDIcon"; function App() { - const { theme } = useTheme(); const categoryApi = useCategoryApi(); const categoryStore = useCategoryStore(); const configApi = useConfigApi(); const configStore = useConfigStore(); + const [opened, { toggle }] = useDisclosure(); + const [adminMode, setAdminMode] = useState(false); + const location = useLocation(); + // Get platform config useEffect(() => { configApi @@ -54,35 +63,60 @@ function App() { }); }, [categoryStore.refresh]); + useEffect(() => { + setAdminMode(false); + if (location.pathname.startsWith("/admin")) { + setAdminMode(true); + } + }, [location.pathname]); + return ( <> - - - - - - - }> - {useRoutes(routes)} - - - - - - - + + + + + {!adminMode && ( + <> + {NavItems?.map((item) => ( + + ))} + + )} + + + }> + {useRoutes(routes)} + + + ); } diff --git a/web/src/components/layouts/withGame.tsx b/web/src/components/layouts/withGame.tsx index a63eaec1..8d947aa9 100644 --- a/web/src/components/layouts/withGame.tsx +++ b/web/src/components/layouts/withGame.tsx @@ -34,7 +34,9 @@ export default function withGame(WrappedComponent: React.ComponentType) { <> - + + 距离结束还剩 + void; + }; + adminMode?: boolean; +} + +export default function Navbar(props: NavbarProps) { + const { burger, adminMode } = props; const authStore = useAuthStore(); const configStore = useConfigStore(); const teamStore = useTeamStore(); @@ -27,9 +82,6 @@ export default function Navbar() { keepTransitions: true, }); - const [adminMode, setAdminMode] = useState(false); - const location = useLocation(); - function logout() { authStore.setPgsToken(""); authStore.setUser(undefined); @@ -37,13 +89,6 @@ export default function Navbar() { navigate("/login"); } - useEffect(() => { - setAdminMode(false); - if (location.pathname.startsWith("/admin")) { - setAdminMode(true); - } - }, [location.pathname]); - return ( - + + - - - {!adminMode && ( - <> - - - - {authStore?.user?.group === "admin" && ( + + + + {!adminMode && ( + <> + {NavItems?.map((item) => ( + + ))} + {authStore?.user?.group === "admin" && ( + + )} + + )} + {adminMode && ( + <> - )} - - )} - {adminMode && ( - <> - - - - - - - - )} - + {AdminNavItems?.map((item) => ( + + ))} + + )} + + - + + + + + + + + + + ); diff --git a/web/src/pages/admin/challenges/index.tsx b/web/src/pages/admin/challenges/index.tsx index ff8de263..d761875c 100644 --- a/web/src/pages/admin/challenges/index.tsx +++ b/web/src/pages/admin/challenges/index.tsx @@ -258,7 +258,7 @@ export default function Page() { {challenges?.map((challenge) => ( - + {challenge?.id} - + - + navigate( diff --git a/web/src/pages/admin/games/index.tsx b/web/src/pages/admin/games/index.tsx index 823bc2d1..be015707 100644 --- a/web/src/pages/admin/games/index.tsx +++ b/web/src/pages/admin/games/index.tsx @@ -147,7 +147,7 @@ export default function Page() { return ( <> - + - + {game?.id} - + {game?.poster?.name && ( - + { navigate( diff --git a/web/src/pages/admin/teams/index.tsx b/web/src/pages/admin/teams/index.tsx index d85e0812..98d2090e 100644 --- a/web/src/pages/admin/teams/index.tsx +++ b/web/src/pages/admin/teams/index.tsx @@ -220,7 +220,7 @@ export default function Page() { {team?.id} - + {team?.email} {team?.description} - + { setSelectedTeam(team); diff --git a/web/src/pages/admin/users/index.tsx b/web/src/pages/admin/users/index.tsx index 13021276..cc193edb 100644 --- a/web/src/pages/admin/users/index.tsx +++ b/web/src/pages/admin/users/index.tsx @@ -219,7 +219,7 @@ export default function Page() { {user?.id} - + {user?.email} {user?.group} - + { setSelectedUser(user); diff --git a/web/src/pages/games/[id]/challenges.tsx b/web/src/pages/games/[id]/challenges.tsx index 1a2af86a..1dba87c4 100644 --- a/web/src/pages/games/[id]/challenges.tsx +++ b/web/src/pages/games/[id]/challenges.tsx @@ -28,7 +28,6 @@ import { Stack, Text, Title, - Transition, UnstyledButton, } from "@mantine/core"; import { useDisclosure } from "@mantine/hooks"; @@ -204,7 +203,18 @@ function Page() { diff --git a/web/src/pages/login.tsx b/web/src/pages/login.tsx index c8f3cafa..3e799a2a 100644 --- a/web/src/pages/login.tsx +++ b/web/src/pages/login.tsx @@ -82,7 +82,6 @@ export default function Page() { position: "fixed", top: "50%", left: "50%", - zIndex: -1, transform: "translate(-50%, -50%)", }} className={"no-select"} diff --git a/web/src/pages/register.tsx b/web/src/pages/register.tsx index b4f9024d..2ed4ac8f 100644 --- a/web/src/pages/register.tsx +++ b/web/src/pages/register.tsx @@ -102,7 +102,6 @@ export default function Page() { position: "fixed", top: "50%", left: "50%", - zIndex: -1, transform: "translate(-50%, -50%)", }} className={"no-select"}