From b60dfdfb425357d9246e2f76b99364da634da205 Mon Sep 17 00:00:00 2001 From: NeonXP Date: Sun, 21 Jan 2024 01:46:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=84=D1=80=D0=BE=D0=BD=D1=82=D0=B5=D0=BD=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/App.jsx | 7 +++- frontend/src/assets/styles.css | 5 ++- frontend/src/components/Layout.jsx | 63 +++++++----------------------- frontend/src/pages/Quests.jsx | 29 ++++++++++---- frontend/src/pages/User.jsx | 34 ++++++++++++++++ 5 files changed, 78 insertions(+), 60 deletions(-) create mode 100644 frontend/src/pages/User.jsx diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index a94c4ce..230cdba 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,16 +1,18 @@ import { Navigate, Route, RouterProvider, createBrowserRouter, createRoutesFromElements, useLocation, useRouteLoaderData } from 'react-router-dom' import PropTypes from 'prop-types' +import { UserProvider } from './store/user' +import { ajax } from './utils/fetch' + import Layout from './components/Layout' import Index from './pages/Index' import Login from './pages/Login' import Register from './pages/Register' import NoMatch from './pages/NoMatch' -import { UserProvider } from './store/user' -import { ajax } from './utils/fetch' import Engine from './pages/Engine' import Quests from './pages/Quests' +import User from './pages/User' const router = createBrowserRouter( createRoutesFromElements( @@ -30,6 +32,7 @@ const router = createBrowserRouter( element={} loader={() => ajax('/api/games').catch(x => { console.log(x); return null })} /> + } /> } /> } /> { @@ -34,65 +34,32 @@ const AppLayout = () => { link: '/quests' }, { - key: 'user', - label: user.username, - children: [ - { - type: 'group', - key: 'exp', - label: ( - - {user.level} уровень - {user.experience} опыт - ) - }, - { - type: 'group', - key: 'progress', - label: - }, - { - type: 'group', - key: 'nextLevel', - label: `Следующий уровень - ${user.expToNextLevel} очков опыта` - }, - { - key: 'logout', - label: 'Выход', - handler: logout - } - ] + key: 'me', + label: `${user.username} [${user.level}]`, + link: '/me' + }, + { + key: 'logout', + label: 'Выход', + onClick: logout } ] } const menuHandler = (x) => { - const item = getItemByPath(items, x.keyPath) + const item = items.find(y => y.key === x.key) if (item.link) { navigate(item.link) } - if (item.handler) { item.handler() } - } - - const getItemByPath = (items, path) => { - const x = path.pop() - const item = items.find(y => y.key === x) - if (path.length === 0) { - return item - } - return getItemByPath(item.children, path) } return ( -
+
} + style={{ width: '100%' }} />
diff --git a/frontend/src/pages/Quests.jsx b/frontend/src/pages/Quests.jsx index 207c844..8c5e509 100644 --- a/frontend/src/pages/Quests.jsx +++ b/frontend/src/pages/Quests.jsx @@ -2,10 +2,10 @@ import { useLoaderData, useNavigate } from 'react-router-dom' import Markdown from 'react-markdown' import remarkGfm from 'remark-gfm' import moment from 'moment/min/moment-with-locales' -import { Avatar, Typography, Button, Space, Card } from 'antd' +import { Avatar, Typography, Button, Space, Card, Popover } from 'antd' import { UserProvider } from '../store/user' -const { Title } = Typography +const { Title, Paragraph } = Typography const Quests = () => { moment.locale('ru') @@ -22,10 +22,25 @@ const Quests = () => { const renderItem = (user, navigate, item) => { const actions = [ - Оп: {item.points}, - Ур: {item.taskCount}, + Квесты бывают двух типов:
  • Виртуальные - проходимые из дома
  • Полевые - проходимые в городе Казани
} + title="Тип квеста"> + + {item.type === 'city' ? 'Полевой' : 'Виртуальный'} + +
, + Вы получите {item.points} очков опыта за выполнение этого квеста.
Чем сложнее квест - тем больше за него опыта!} + title='Опыт за выполнения квеста'> + {item.points} ОО +
, + + {item.taskCount} ур + , <>{moment(item.createdAt).fromNow()}, - <>Автор(ы) {item.authors.map(a => a.username)} + <>Автор {item.authors.map(a => a.username)} ] let questAction = (Необходимо войти) @@ -41,11 +56,9 @@ const renderItem = (user, navigate, item) => {  {item.title}} style={{ marginBottom: 8 }} > - - {item.description} diff --git a/frontend/src/pages/User.jsx b/frontend/src/pages/User.jsx new file mode 100644 index 0000000..f7852f9 --- /dev/null +++ b/frontend/src/pages/User.jsx @@ -0,0 +1,34 @@ +import { Avatar, Popover, Progress, Space, Typography } from 'antd' +import { UserProvider } from '../store/user' +import Markdown from 'react-markdown' + +const { Paragraph } = Typography + +const User = () => { + const { user } = UserProvider.useContainer() + if (user == null) { + return (Загрузка...) + } + + return (<> +

{user.username}

+ Уровень: {user.level} ур + Очков опыта: {user.experience} ОО + Следующий уровень: {user.expToNextLevel} ОО + + {user.games.map(item => {item.description}
} + > + + )} + ) +} + +export default User