mobile
This commit is contained in:
+59
-104
@@ -4,15 +4,13 @@ import {
|
|||||||
BarChartOutlined,
|
BarChartOutlined,
|
||||||
CameraOutlined,
|
CameraOutlined,
|
||||||
LogoutOutlined,
|
LogoutOutlined,
|
||||||
MenuOutlined,
|
|
||||||
OrderedListOutlined,
|
OrderedListOutlined,
|
||||||
UserOutlined,
|
UserOutlined,
|
||||||
} from '@ant-design/icons'
|
} from '@ant-design/icons'
|
||||||
import { Avatar, Button, Drawer, Layout, Menu, Result, Space, Tag, Typography } from 'antd'
|
import { Avatar, Button, Grid, Layout, Menu, Result, Space, Tag, Typography } from 'antd'
|
||||||
import { Outlet, useLocation, useNavigate } from 'react-router-dom'
|
import { Outlet, useLocation, useNavigate } from 'react-router-dom'
|
||||||
import { ROLE_MANAGE_AREA, ROLE_MANAGE_ATTRACTION } from '@/auth/roles'
|
import { ROLE_MANAGE_AREA, ROLE_MANAGE_ATTRACTION } from '@/auth/roles'
|
||||||
import { useAuth } from '@/auth/AuthContext'
|
import { useAuth } from '@/auth/AuthContext'
|
||||||
import { useIsMobile } from '@/hooks/useIsMobile'
|
|
||||||
|
|
||||||
const { Header, Sider, Content } = Layout
|
const { Header, Sider, Content } = Layout
|
||||||
|
|
||||||
@@ -25,20 +23,15 @@ export function AdminLayout() {
|
|||||||
const { email, roles, logout } = useAuth()
|
const { email, roles, logout } = useAuth()
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const isMobile = useIsMobile()
|
const screens = Grid.useBreakpoint()
|
||||||
const [menuOpen, setMenuOpen] = useState(false)
|
// Узкие экраны/панели: без текста в шапке, контент с меньшими отступами.
|
||||||
|
const isNarrow = !screens.md // < 768
|
||||||
|
const isCompactHeader = !screens.lg // < 992
|
||||||
|
const [collapsed, setCollapsed] = useState(false)
|
||||||
|
|
||||||
const hasManageArea = roles.includes(ROLE_MANAGE_AREA)
|
const hasManageArea = roles.includes(ROLE_MANAGE_AREA)
|
||||||
const hasManageAttraction = roles.includes(ROLE_MANAGE_ATTRACTION)
|
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) {
|
if (!hasManageArea && !hasManageAttraction) {
|
||||||
return (
|
return (
|
||||||
<Result
|
<Result
|
||||||
@@ -71,31 +64,6 @@ export function AdminLayout() {
|
|||||||
|
|
||||||
const selectedKey = '/' + (location.pathname.split('/')[1] ?? '')
|
const selectedKey = '/' + (location.pathname.split('/')[1] ?? '')
|
||||||
|
|
||||||
const menu = (
|
|
||||||
<Menu
|
|
||||||
mode="inline"
|
|
||||||
selectedKeys={[selectedKey]}
|
|
||||||
items={menuItems}
|
|
||||||
onClick={({ key }) => {
|
|
||||||
navigate(key)
|
|
||||||
setMenuOpen(false)
|
|
||||||
}}
|
|
||||||
style={{ borderRight: 0, paddingTop: 8 }}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
|
|
||||||
const roleTags = (
|
|
||||||
<Space size={4} wrap>
|
|
||||||
{roles
|
|
||||||
.filter((role) => ROLE_LABELS[role])
|
|
||||||
.map((role) => (
|
|
||||||
<Tag key={role} color="gold">
|
|
||||||
{ROLE_LABELS[role]}
|
|
||||||
</Tag>
|
|
||||||
))}
|
|
||||||
</Space>
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout style={{ minHeight: '100vh' }}>
|
<Layout style={{ minHeight: '100vh' }}>
|
||||||
<Header
|
<Header
|
||||||
@@ -104,83 +72,70 @@ export function AdminLayout() {
|
|||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
gap: 16,
|
gap: 16,
|
||||||
paddingInline: isMobile ? 12 : undefined,
|
paddingInline: isNarrow ? 12 : undefined,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{isMobile ? (
|
<Typography.Title
|
||||||
<>
|
level={4}
|
||||||
<Space size={4}>
|
ellipsis
|
||||||
<Button
|
style={{ color: '#fff', margin: 0, whiteSpace: 'nowrap' }}
|
||||||
type="text"
|
>
|
||||||
icon={<MenuOutlined />}
|
{isCompactHeader ? 'Городар' : 'Городар · Админ-панель'}
|
||||||
aria-label="Меню"
|
</Typography.Title>
|
||||||
onClick={() => setMenuOpen(true)}
|
<Space size="middle" style={{ minWidth: 0 }}>
|
||||||
style={{ color: '#fff' }}
|
{!isCompactHeader && (
|
||||||
/>
|
<Space size={4} wrap>
|
||||||
<Typography.Title level={4} style={{ color: '#fff', margin: 0 }}>
|
{roles
|
||||||
Городар
|
.filter((role) => ROLE_LABELS[role])
|
||||||
</Typography.Title>
|
.map((role) => (
|
||||||
|
<Tag key={role} color="gold">
|
||||||
|
{ROLE_LABELS[role]}
|
||||||
|
</Tag>
|
||||||
|
))}
|
||||||
</Space>
|
</Space>
|
||||||
|
)}
|
||||||
|
<Space size={8} style={{ minWidth: 0 }}>
|
||||||
|
<Avatar size="small" icon={<UserOutlined />} />
|
||||||
|
{!isNarrow && (
|
||||||
|
<Typography.Text
|
||||||
|
ellipsis
|
||||||
|
style={{ color: 'rgba(255,255,255,0.85)', maxWidth: 240 }}
|
||||||
|
>
|
||||||
|
{email}
|
||||||
|
</Typography.Text>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
type="text"
|
type="text"
|
||||||
aria-label="Выйти"
|
aria-label="Выйти"
|
||||||
|
title="Выйти"
|
||||||
icon={<LogoutOutlined />}
|
icon={<LogoutOutlined />}
|
||||||
onClick={logout}
|
onClick={logout}
|
||||||
style={{ color: 'rgba(255,255,255,0.85)' }}
|
style={{ color: 'rgba(255,255,255,0.85)' }}
|
||||||
/>
|
>
|
||||||
</>
|
{isNarrow ? null : 'Выйти'}
|
||||||
) : (
|
</Button>
|
||||||
<>
|
</Space>
|
||||||
<Space size="middle">
|
</Space>
|
||||||
<Typography.Title level={4} style={{ color: '#fff', margin: 0 }}>
|
|
||||||
Городар · Админ-панель
|
|
||||||
</Typography.Title>
|
|
||||||
</Space>
|
|
||||||
<Space size="middle">
|
|
||||||
{roleTags}
|
|
||||||
<Space size={8}>
|
|
||||||
<Avatar size="small" icon={<UserOutlined />} />
|
|
||||||
<Typography.Text style={{ color: 'rgba(255,255,255,0.85)' }}>{email}</Typography.Text>
|
|
||||||
<Button
|
|
||||||
type="text"
|
|
||||||
icon={<LogoutOutlined />}
|
|
||||||
onClick={logout}
|
|
||||||
style={{ color: 'rgba(255,255,255,0.85)' }}
|
|
||||||
>
|
|
||||||
Выйти
|
|
||||||
</Button>
|
|
||||||
</Space>
|
|
||||||
</Space>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Header>
|
</Header>
|
||||||
<Layout>
|
<Layout>
|
||||||
{isMobile ? (
|
{/* Сайдбар сворачивается до иконок автоматически ниже md и вручную тумблером снизу. */}
|
||||||
<Drawer
|
<Sider
|
||||||
title="Меню"
|
theme="light"
|
||||||
placement="left"
|
width={224}
|
||||||
width={288}
|
collapsible
|
||||||
open={menuOpen}
|
collapsed={collapsed}
|
||||||
onClose={() => setMenuOpen(false)}
|
onCollapse={setCollapsed}
|
||||||
styles={{ body: { padding: 0 } }}
|
breakpoint="md"
|
||||||
>
|
>
|
||||||
<div style={{ padding: '8px 24px' }}>
|
<Menu
|
||||||
<Space size={8}>
|
mode="inline"
|
||||||
<Avatar size="small" icon={<UserOutlined />} />
|
selectedKeys={[selectedKey]}
|
||||||
<Typography.Text style={{ maxWidth: 180 }} ellipsis>
|
items={menuItems}
|
||||||
{email}
|
onClick={({ key }) => navigate(key)}
|
||||||
</Typography.Text>
|
style={{ height: '100%', borderRight: 0, paddingTop: 8 }}
|
||||||
</Space>
|
/>
|
||||||
<div style={{ marginTop: 8 }}>{roleTags}</div>
|
</Sider>
|
||||||
</div>
|
<Content style={{ padding: isNarrow ? 16 : 24 }}>
|
||||||
{menu}
|
|
||||||
</Drawer>
|
|
||||||
) : (
|
|
||||||
<Sider theme="light" width={220}>
|
|
||||||
{menu}
|
|
||||||
</Sider>
|
|
||||||
)}
|
|
||||||
<Content style={{ padding: isMobile ? 16 : 24 }}>
|
|
||||||
<Outlet />
|
<Outlet />
|
||||||
</Content>
|
</Content>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|||||||
@@ -196,9 +196,9 @@ export function PhotoGallery({
|
|||||||
cover={
|
cover={
|
||||||
<Image
|
<Image
|
||||||
src={photo.photoUrl}
|
src={photo.photoUrl}
|
||||||
height={180}
|
|
||||||
width="100%"
|
width="100%"
|
||||||
style={{ objectFit: 'cover' }}
|
wrapperStyle={{ width: '100%' }}
|
||||||
|
style={{ aspectRatio: '4 / 3', objectFit: 'cover' }}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ export function VisitListPage() {
|
|||||||
<Card size="small" style={{ marginBottom: 16 }}>
|
<Card size="small" style={{ marginBottom: 16 }}>
|
||||||
<Form
|
<Form
|
||||||
form={form}
|
form={form}
|
||||||
layout="inline"
|
layout={isMobile ? 'vertical' : 'inline'}
|
||||||
onFinish={applyFilters}
|
onFinish={applyFilters}
|
||||||
style={{ rowGap: 12, flexWrap: 'wrap', alignItems: 'center' }}
|
style={{ rowGap: 12, flexWrap: 'wrap', alignItems: 'center' }}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user