App.tsx
3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { useEffect } from 'react';
import { App as AntdApp, ConfigProvider } from 'antd';
import zhCN from 'antd/locale/zh_CN';
import { themeConfig } from '@/theme/themeConfig';
import { useBootstrap } from '@/features/heatmap/useBootstrap';
import { HeaderBar } from '@/layout/HeaderBar';
import { MapStage } from '@/features/heatmap/MapStage';
import { FilterPanel } from '@/features/heatmap/panels/FilterPanel';
import { StatsPanel } from '@/features/heatmap/panels/StatsPanel';
import { BucketDrawer } from '@/features/heatmap/detail/BucketDrawer';
import { useHeatmapStore } from '@/store/useHeatmapStore';
import { useKeyboardShortcuts } from '@/layout/useKeyboardShortcuts';
import '@/theme/design.css';
/**
* 应用根。
*
* 布局:地图全屏铺底,顶栏 + 左右操作栏以毛玻璃卡片浮在地图之上。
* 顶栏和左右栏都可独立收起;视口宽度不足时自动收缩两侧,宽起来再展开。
* 明细抽屉挂在地图之外,由 zustand 的 drawerOpen 控制显隐。
*/
export default function App() {
useBootstrap();
useKeyboardShortcuts();
const leftCollapsed = useHeatmapStore((s) => s.leftCollapsed);
const rightCollapsed = useHeatmapStore((s) => s.rightCollapsed);
// 记住用户是否手动干预过窄屏自动收缩:手动展开后,不因轻微抖动反复收起。
useEffect(() => {
const apply = () => {
const w = window.innerWidth;
const store = useHeatmapStore.getState();
if (w < 1180) {
// 窄屏:两侧都收起,把地图完整让出来
store.setCollapsed(true, true);
} else if (w < 1440) {
// 中等:只收右侧统计栏
store.setCollapsed(store.leftCollapsed, true);
}
};
apply();
window.addEventListener('resize', apply);
return () => window.removeEventListener('resize', apply);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const bodyClass = [
'hm-body',
leftCollapsed && 'is-left-collapsed',
rightCollapsed && 'is-right-collapsed',
]
.filter(Boolean)
.join(' ');
return (
<ConfigProvider locale={zhCN} theme={themeConfig}>
<AntdApp>
<div className="hm-app">
<HeaderBar />
<div className={bodyClass}>
<MapStage />
<div className="hm-col--side hm-col--left">
<FilterPanel />
</div>
<div className="hm-col--side hm-col--right">
<StatsPanel />
</div>
<RailToggle side="left" collapsed={leftCollapsed} />
<RailToggle side="right" collapsed={rightCollapsed} />
</div>
<BucketDrawer />
</div>
</AntdApp>
</ConfigProvider>
);
}
/**
* 操作栏收起 / 展开把手。
*
* 挂在 .hm-body 上而不是栏内:栏收起时会整体滑出视口,把手若在里面会跟着消失,
* 用户就没法再拉回来了。用 chevron 朝向表达当前状态与点击后的动作。
*/
function RailToggle({ side, collapsed }: { side: 'left' | 'right'; collapsed: boolean }) {
const toggle = useHeatmapStore((s) => (side === 'left' ? s.toggleLeft : s.toggleRight));
const key = side === 'left' ? '[' : ']';
const pointLeft = side === 'left' ? !collapsed : collapsed;
return (
<button
type="button"
className={`hm-rail-toggle hm-rail-toggle--${side}`}
onClick={toggle}
aria-label={collapsed ? '展开操作栏' : '收起操作栏'}
title={`${collapsed ? '展开' : '收起'} (${key})`}
>
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
className={pointLeft ? 'hm-rail-toggle__icon' : 'hm-rail-toggle__icon is-flip'}
aria-hidden
>
<path
d="M15 5l-7 7 7 7"
stroke="currentColor"
strokeWidth="2.2"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
</button>
);
}