fix(UI): improve global map banner display logic (#702)
This commit is contained in:
parent
2d8a02f257
commit
5517e826aa
|
|
@ -0,0 +1,10 @@
|
|||
export function hasDownloadedGlobalMap(
|
||||
globalMapKey: string | null | undefined,
|
||||
storedMapFiles: Array<{ name: string }>
|
||||
): boolean {
|
||||
if (!globalMapKey) {
|
||||
return false
|
||||
}
|
||||
|
||||
return storedMapFiles.some((file) => file.name === globalMapKey || /^\d{8}\.pmtiles$/.test(file.name))
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ import type { CollectionWithStatus } from '../../../types/collections'
|
|||
import ActiveDownloads from '~/components/ActiveDownloads'
|
||||
import Alert from '~/components/Alert'
|
||||
import { formatBytes } from '~/lib/util'
|
||||
import { hasDownloadedGlobalMap } from '~/lib/global_map_banner'
|
||||
|
||||
const CURATED_COLLECTIONS_KEY = 'curated-map-collections'
|
||||
const GLOBAL_MAP_INFO_KEY = 'global-map-info'
|
||||
|
|
@ -45,6 +46,7 @@ export default function MapsManager(props: {
|
|||
queryFn: () => api.getGlobalMapInfo(),
|
||||
refetchOnWindowFocus: false,
|
||||
})
|
||||
const globalMapAlreadyDownloaded = hasDownloadedGlobalMap(globalMapInfo?.key, props.maps.regionFiles)
|
||||
|
||||
const downloadGlobalMap = useMutation({
|
||||
mutationFn: () => api.downloadGlobalMap(),
|
||||
|
|
@ -251,7 +253,23 @@ export default function MapsManager(props: {
|
|||
}}
|
||||
/>
|
||||
)}
|
||||
{globalMapInfo && (
|
||||
{globalMapInfo && globalMapAlreadyDownloaded && (
|
||||
<Alert
|
||||
title="Global Map Installed"
|
||||
message={`Your global map build ${globalMapInfo.date} (${formatBytes(globalMapInfo.size, 1)}) is stored locally and ready for offline use.`}
|
||||
type="success"
|
||||
variant="bordered"
|
||||
className="mt-8"
|
||||
icon="IconCircleCheck"
|
||||
buttonProps={{
|
||||
variant: 'secondary',
|
||||
children: 'Download latest build',
|
||||
icon: 'IconRefresh',
|
||||
onClick: () => confirmGlobalMapDownload(),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{globalMapInfo && !globalMapAlreadyDownloaded && (
|
||||
<Alert
|
||||
title="Global Map Coverage Available"
|
||||
message={`Download a complete worldwide map from Protomaps (${formatBytes(globalMapInfo.size, 1)}, build ${globalMapInfo.date}). This is a large file but covers the entire planet — no individual region downloads needed.`}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
import * as assert from 'node:assert/strict'
|
||||
import { test } from 'node:test'
|
||||
|
||||
import { hasDownloadedGlobalMap } from '../../inertia/lib/global_map_banner.js'
|
||||
|
||||
test('returns true when the global map key already exists on disk', () => {
|
||||
assert.equal(
|
||||
hasDownloadedGlobalMap('20260402.pmtiles', [
|
||||
{ name: '20260402.pmtiles' },
|
||||
{ name: 'california.pmtiles' },
|
||||
]),
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
test('returns false when the global map key is missing', () => {
|
||||
assert.equal(
|
||||
hasDownloadedGlobalMap('20260402.pmtiles', [
|
||||
{ name: 'california.pmtiles' },
|
||||
]),
|
||||
false
|
||||
)
|
||||
})
|
||||
|
||||
test('returns true when an older global map build is already on disk', () => {
|
||||
assert.equal(
|
||||
hasDownloadedGlobalMap('20260402.pmtiles', [
|
||||
{ name: '20260315.pmtiles' },
|
||||
{ name: 'california.pmtiles' },
|
||||
]),
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
test('returns false when there is no global map info', () => {
|
||||
assert.equal(hasDownloadedGlobalMap(undefined, [{ name: '20260402.pmtiles' }]), false)
|
||||
})
|
||||
Loading…
Reference in New Issue