fix(UI): improve global map banner display logic (#702)
This commit is contained in:
parent
d1dc8faf49
commit
29f74e9525
|
|
@ -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 ActiveDownloads from '~/components/ActiveDownloads'
|
||||||
import Alert from '~/components/Alert'
|
import Alert from '~/components/Alert'
|
||||||
import { formatBytes } from '~/lib/util'
|
import { formatBytes } from '~/lib/util'
|
||||||
|
import { hasDownloadedGlobalMap } from '~/lib/global_map_banner'
|
||||||
|
|
||||||
const CURATED_COLLECTIONS_KEY = 'curated-map-collections'
|
const CURATED_COLLECTIONS_KEY = 'curated-map-collections'
|
||||||
const GLOBAL_MAP_INFO_KEY = 'global-map-info'
|
const GLOBAL_MAP_INFO_KEY = 'global-map-info'
|
||||||
|
|
@ -45,6 +46,7 @@ export default function MapsManager(props: {
|
||||||
queryFn: () => api.getGlobalMapInfo(),
|
queryFn: () => api.getGlobalMapInfo(),
|
||||||
refetchOnWindowFocus: false,
|
refetchOnWindowFocus: false,
|
||||||
})
|
})
|
||||||
|
const globalMapAlreadyDownloaded = hasDownloadedGlobalMap(globalMapInfo?.key, props.maps.regionFiles)
|
||||||
|
|
||||||
const downloadGlobalMap = useMutation({
|
const downloadGlobalMap = useMutation({
|
||||||
mutationFn: () => api.downloadGlobalMap(),
|
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
|
<Alert
|
||||||
title="Global Map Coverage Available"
|
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.`}
|
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