Skip to content

Commit 2dd728a

Browse files
committed
feat: improve map ui
1 parent acc072d commit 2dd728a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/components/editor/floatingMap/FloatingMap.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { createPortal } from 'react-dom'
77
import { Rnd, RndResizeCallback } from 'react-rnd'
88
import { useWindowSize } from 'react-use'
99

10+
import { Level } from '../../../models/operation'
1011
import { sendMessage, useMessage } from '../../../utils/messenger'
1112
import { useLazyStorage } from '../../../utils/useLazyStorage'
1213
import { useFloatingMap } from './FloatingMapContext'
@@ -25,14 +26,15 @@ interface FloatingMapConfig {
2526
y: number
2627
width: number
2728
height: number
29+
level?: Level
2830
}
2931

3032
const UID = 'floating-map'
3133
const STORAGE_KEY = `copilot-${UID}`
3234

3335
const HEADER_CLASS = 'floating-map-header'
3436

35-
const HEADER_HEIGHT = 16
37+
const HEADER_HEIGHT = 36
3638
const ASPECT_RATIO = 16 / 9
3739
const MIN_HEIGHT = 150 + HEADER_HEIGHT
3840
const MIN_WIDTH = 150 * ASPECT_RATIO
@@ -54,6 +56,7 @@ export function FloatingMap() {
5456
y: window.innerHeight - DEFAULT_HEIGHT,
5557
width: DEFAULT_WIDTH,
5658
height: DEFAULT_HEIGHT,
59+
level: undefined,
5760
},
5861
// merge two values in case the saved value is missing some properties
5962
(savedValue, defaultValue) => ({ ...defaultValue, ...savedValue }),
@@ -77,6 +80,7 @@ export function FloatingMap() {
7780
useEffect(() => {
7881
// when level changes, the iframe should reload
7982
setMapStatus(MapStatus.Loading)
83+
setConfig((cfg) => ({ ...cfg, level }))
8084
}, [level])
8185

8286
const setMapState = useCallback(() => {
@@ -204,9 +208,8 @@ export function FloatingMap() {
204208
</Rnd>
205209
) : (
206210
<Card
207-
className="absolute !p-0 overflow-hidden pointer-events-auto"
211+
className="absolute !p-0 overflow-hidden pointer-events-auto left-4 bottom-4"
208212
elevation={2}
209-
style={{ left: 0, bottom: 0 }}
210213
>
211214
<FloatingMapHeader config={config} setConfig={setConfig} />
212215
</Card>
@@ -238,13 +241,14 @@ function FloatingMapHeader({
238241
>
239242
<Button
240243
minimal
241-
small={!config.show}
242-
className="min-h-0 !py-0"
244+
style={{ height: HEADER_HEIGHT }}
245+
className="px-4"
243246
title={config.show ? '隐藏地图' : '显示地图'}
244247
icon={config.show ? 'caret-down' : 'caret-up'}
245248
onClick={() => setConfig({ ...config, show: !config.show })}
246249
>
247-
{!config.show && '地图'}
250+
地图
251+
{config.show && ` ${config.level?.name}`}
248252
</Button>
249253
</div>
250254
)

0 commit comments

Comments
 (0)