From f6fd6d79a0743a7fbb432b57b3bba308403edfbc Mon Sep 17 00:00:00 2001 From: "a.ilin" Date: Tue, 6 Oct 2026 10:23:46 +0300 Subject: [PATCH] mobile --- src/auth/LoginScreen.tsx | 3 +- src/hooks/useIsMobile.ts | 7 + src/layouts/AdminLayout.tsx | 141 +++++++++++++----- src/pages/areas/AreaListPage.tsx | 4 + .../attractions/AttractionDetailPage.tsx | 6 +- src/pages/attractions/AttractionForm.tsx | 25 +++- src/pages/attractions/AttractionListPage.tsx | 18 ++- src/pages/sets/SetListPage.tsx | 17 ++- src/pages/visits/VisitListPage.tsx | 30 +++- 9 files changed, 194 insertions(+), 57 deletions(-) create mode 100644 src/hooks/useIsMobile.ts diff --git a/src/auth/LoginScreen.tsx b/src/auth/LoginScreen.tsx index e77f956..81eb507 100644 --- a/src/auth/LoginScreen.tsx +++ b/src/auth/LoginScreen.tsx @@ -57,9 +57,10 @@ export function LoginScreen() { alignItems: 'center', justifyContent: 'center', background: '#f0f2f5', + padding: 16, }} > - + Городар · Админ-панель diff --git a/src/hooks/useIsMobile.ts b/src/hooks/useIsMobile.ts new file mode 100644 index 0000000..addab32 --- /dev/null +++ b/src/hooks/useIsMobile.ts @@ -0,0 +1,7 @@ +import { Grid } from 'antd' + +/** true на экранах уже md (768px) — телефонная вёрстка. */ +export function useIsMobile(): boolean { + const screens = Grid.useBreakpoint() + return !screens.md +} diff --git a/src/layouts/AdminLayout.tsx b/src/layouts/AdminLayout.tsx index 4506481..9b84e5b 100644 --- a/src/layouts/AdminLayout.tsx +++ b/src/layouts/AdminLayout.tsx @@ -1,15 +1,18 @@ +import { useState } from 'react' import { ApartmentOutlined, BarChartOutlined, CameraOutlined, LogoutOutlined, + MenuOutlined, OrderedListOutlined, UserOutlined, } from '@ant-design/icons' -import { Avatar, Button, Layout, Menu, Result, Space, Tag, Typography } from 'antd' +import { Avatar, Button, Drawer, Layout, Menu, Result, Space, Tag, Typography } from 'antd' import { Outlet, useLocation, useNavigate } from 'react-router-dom' import { ROLE_MANAGE_AREA, ROLE_MANAGE_ATTRACTION } from '@/auth/roles' import { useAuth } from '@/auth/AuthContext' +import { useIsMobile } from '@/hooks/useIsMobile' const { Header, Sider, Content } = Layout @@ -22,10 +25,20 @@ export function AdminLayout() { const { email, roles, logout } = useAuth() const location = useLocation() const navigate = useNavigate() + const isMobile = useIsMobile() + const [menuOpen, setMenuOpen] = useState(false) const hasManageArea = roles.includes(ROLE_MANAGE_AREA) const hasManageAttraction = roles.includes(ROLE_MANAGE_ATTRACTION) + // При переходе десктоп↔мобильный открытый Drawer теряет смысл — сбрасываем + // во время рендера (паттерн «adjust state when props change» из доков React). + const [wasMobile, setWasMobile] = useState(isMobile) + if (wasMobile !== isMobile) { + setWasMobile(isMobile) + setMenuOpen(false) + } + if (!hasManageArea && !hasManageAttraction) { return ( { + navigate(key) + setMenuOpen(false) + }} + style={{ borderRight: 0, paddingTop: 8 }} + /> + ) + + const roleTags = ( + + {roles + .filter((role) => ROLE_LABELS[role]) + .map((role) => ( + + {ROLE_LABELS[role]} + + ))} + + ) + return (
- - - Городар · Админ-панель - - - - - {roles - .filter((role) => ROLE_LABELS[role]) - .map((role) => ( - - {ROLE_LABELS[role]} - - ))} - - - } /> - {email} + {isMobile ? ( + <> + + - - + /> + + ) : ( + <> + + + Городар · Админ-панель + + + + {roleTags} + + } /> + {email} + + + + + )}
- - navigate(key)} - style={{ height: '100%', borderRight: 0, paddingTop: 8 }} - /> - - + {isMobile ? ( + setMenuOpen(false)} + styles={{ body: { padding: 0 } }} + > +
+ + } /> + + {email} + + +
{roleTags}
+
+ {menu} +
+ ) : ( + + {menu} + + )} + diff --git a/src/pages/areas/AreaListPage.tsx b/src/pages/areas/AreaListPage.tsx index 6301d67..f1cd942 100644 --- a/src/pages/areas/AreaListPage.tsx +++ b/src/pages/areas/AreaListPage.tsx @@ -6,6 +6,7 @@ import { createArea, fetchAreas, updateArea } from '@/api/areas' import { notifyApiError, notifySuccess } from '@/api/errors' import type { Area } from '@/api/types' import { AreaTreeSelect } from '@/components/AreaTreeSelect' +import { useIsMobile } from '@/hooks/useIsMobile' interface TrailItem { id: string @@ -26,6 +27,7 @@ const PAGE_SIZE = 20 export function AreaListPage() { const queryClient = useQueryClient() + const isMobile = useIsMobile() const [parentId, setParentId] = useState(null) const [trail, setTrail] = useState([]) const [page, setPage] = useState(0) @@ -167,6 +169,7 @@ export function AreaListPage() { columns={columns} dataSource={data?.content ?? []} loading={areasQuery.isLoading} + scroll={{ x: 'max-content' }} locale={{ emptyText: , }} @@ -175,6 +178,7 @@ export function AreaListPage() { pageSize: data?.size ?? PAGE_SIZE, total: data?.totalElements ?? 0, showSizeChanger: false, + simple: isMobile, onChange: (p) => setPage(p - 1), }} /> diff --git a/src/pages/attractions/AttractionDetailPage.tsx b/src/pages/attractions/AttractionDetailPage.tsx index 2a1e767..f323e02 100644 --- a/src/pages/attractions/AttractionDetailPage.tsx +++ b/src/pages/attractions/AttractionDetailPage.tsx @@ -148,7 +148,7 @@ export function AttractionDetailPage() { <>
- + @@ -162,7 +162,7 @@ export function AttractionDetailPage() {
- + {attraction.name} @@ -196,7 +196,7 @@ export function AttractionDetailPage() { - + {iconUrl ? ( ) : ( diff --git a/src/pages/attractions/AttractionForm.tsx b/src/pages/attractions/AttractionForm.tsx index f9624bf..a5b8990 100644 --- a/src/pages/attractions/AttractionForm.tsx +++ b/src/pages/attractions/AttractionForm.tsx @@ -2,6 +2,7 @@ import type { FormInstance } from 'antd' import { Button, Form, Input, InputNumber, Select, Space } from 'antd' import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons' import type { CreateAttractionRequest, CvProfile, UpdateAttractionRequest } from '@/api/types' +import { useIsMobile } from '@/hooks/useIsMobile' import { cvProfileOptions } from '@/utils/format' export interface AttractionFormValues { @@ -74,6 +75,8 @@ export function AttractionForm({ form: FormInstance initialValues?: AttractionFormInitialValues }) { + const isMobile = useIsMobile() + return (
- + @@ -130,7 +138,7 @@ export function AttractionForm({ @@ -148,22 +156,25 @@ export function AttractionForm({ {(fields, { add, remove }) => ( <> {fields.map((field) => ( - +
- + remove(field.name)} /> - +
))} diff --git a/src/pages/attractions/AttractionListPage.tsx b/src/pages/attractions/AttractionListPage.tsx index 7db3c8c..df0e294 100644 --- a/src/pages/attractions/AttractionListPage.tsx +++ b/src/pages/attractions/AttractionListPage.tsx @@ -7,6 +7,7 @@ import { createAttraction, fetchAttractions } from '@/api/attractions' import { notifyApiError, notifySuccess } from '@/api/errors' import type { Attraction } from '@/api/types' import { AreaTreeSelect } from '@/components/AreaTreeSelect' +import { useIsMobile } from '@/hooks/useIsMobile' import { cvProfileMeta } from '@/utils/format' import { AttractionForm, @@ -18,6 +19,7 @@ const PAGE_SIZE = 20 export function AttractionListPage() { const navigate = useNavigate() + const isMobile = useIsMobile() const [searchParams, setSearchParams] = useSearchParams() const [areaId, setAreaId] = useState(searchParams.get('area')) const [page, setPage] = useState(0) @@ -109,14 +111,24 @@ export function AttractionListPage() { Достопримечательности - + - @@ -130,12 +142,14 @@ export function AttractionListPage() { columns={columns} dataSource={data?.content ?? []} loading={attractionsQuery.isLoading} + scroll={{ x: 'max-content' }} locale={{ emptyText: }} pagination={{ current: (data?.number ?? 0) + 1, pageSize: data?.size ?? PAGE_SIZE, total: data?.totalElements ?? 0, showSizeChanger: false, + simple: isMobile, onChange: (p) => setPage(p - 1), }} /> diff --git a/src/pages/sets/SetListPage.tsx b/src/pages/sets/SetListPage.tsx index 45f6ca1..e165b82 100644 --- a/src/pages/sets/SetListPage.tsx +++ b/src/pages/sets/SetListPage.tsx @@ -18,6 +18,7 @@ import { notifyApiError, notifySuccess } from '@/api/errors' import { activateSet, archiveSet, createSet, fetchSets, renameSet } from '@/api/sets' import type { AttractionSet } from '@/api/types' import { AreaTreeSelect } from '@/components/AreaTreeSelect' +import { useIsMobile } from '@/hooks/useIsMobile' import { setStatusMeta } from '@/utils/format' import { SetItemsModal } from '@/pages/sets/SetItemsModal' @@ -27,6 +28,7 @@ interface NameFormValues { export function SetListPage() { const queryClient = useQueryClient() + const isMobile = useIsMobile() const [searchParams, setSearchParams] = useSearchParams() const [areaId, setAreaId] = useState(searchParams.get('area')) const [createOpen, setCreateOpen] = useState(false) @@ -165,14 +167,24 @@ export function SetListPage() { Наборы - + - @@ -186,6 +198,7 @@ export function SetListPage() { columns={columns} dataSource={sets} loading={setsQuery.isLoading} + scroll={{ x: 'max-content' }} pagination={false} locale={{ emptyText: }} /> diff --git a/src/pages/visits/VisitListPage.tsx b/src/pages/visits/VisitListPage.tsx index f226536..c6e45e9 100644 --- a/src/pages/visits/VisitListPage.tsx +++ b/src/pages/visits/VisitListPage.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useState, type CSSProperties } from 'react' import { keepPreviousData, useQuery } from '@tanstack/react-query' import { Button, Card, DatePicker, Form, Input, Select, Space, Table, Tag, Typography } from 'antd' import type { ColumnsType } from 'antd/es/table' @@ -9,6 +9,7 @@ import { fetchAttractions } from '@/api/attractions' import { fetchVisits } from '@/api/visits' import type { Visit, VisitFilter } from '@/api/types' import { AreaTreeSelect } from '@/components/AreaTreeSelect' +import { useIsMobile } from '@/hooks/useIsMobile' import { formatConfidence, formatUtc, verdictMeta } from '@/utils/format' const PAGE_SIZE = 20 @@ -23,6 +24,7 @@ interface FilterFormValues { export function VisitListPage() { const [form] = Form.useForm() + const isMobile = useIsMobile() const watchedAreaId = Form.useWatch('areaId', form) const [applied, setApplied] = useState({}) const [page, setPage] = useState(0) @@ -99,6 +101,11 @@ export function VisitListPage() { const data = visitsQuery.data + // На мобиле поля фильтра занимают всю ширину, на десктопе — фиксированные. + const itemStyle: CSSProperties = isMobile ? { width: '100%' } : { marginRight: 12 } + const controlStyle = (desktopWidth: number): CSSProperties => + isMobile ? { width: '100%' } : { width: desktopWidth } + return ( <> @@ -112,14 +119,15 @@ export function VisitListPage() { onFinish={applyFilters} style={{ rowGap: 12, flexWrap: 'wrap', alignItems: 'center' }} > - + form.setFieldValue('attractionId', undefined)} + style={isMobile ? { width: '100%' } : undefined} /> - + + + - - + + @@ -165,11 +177,13 @@ export function VisitListPage() { dataSource={data?.content ?? []} loading={visitsQuery.isLoading} onChange={handleTableChange} + scroll={{ x: 'max-content' }} pagination={{ current: (data?.number ?? 0) + 1, pageSize: data?.size ?? PAGE_SIZE, total: data?.totalElements ?? 0, showSizeChanger: false, + simple: isMobile, showTotal: (total) => `Всего: ${total}`, }} />