Skip to content

Commit b6ac6b1

Browse files
committed
feat(Maps): enhance missing assets warnings
1 parent 400cd74 commit b6ac6b1

File tree

5 files changed

+53
-35
lines changed

5 files changed

+53
-35
lines changed

admin/app/controllers/maps_controller.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ export default class MapsController {
1313
constructor(private mapService: MapService) {}
1414

1515
async index({ inertia }: HttpContext) {
16-
return inertia.render('maps')
16+
const baseAssetsCheck = await this.mapService.checkBaseAssetsExist()
17+
const regionFiles = await this.mapService.listRegions()
18+
return inertia.render('maps', {
19+
maps: {
20+
baseAssetsExist: baseAssetsCheck,
21+
regionFiles: regionFiles.files,
22+
},
23+
})
1724
}
1825

1926
async checkBaseAssets({}: HttpContext) {

admin/inertia/components/layout/MissingBaseAssetsAlert.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.

admin/inertia/pages/maps.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@ import { Head, Link } from '@inertiajs/react'
33
import MapComponent from '~/components/maps/MapComponent'
44
import StyledButton from '~/components/StyledButton'
55
import { IconArrowLeft } from '@tabler/icons-react'
6+
import { FileEntry } from '../../types/files'
7+
import AlertWithButton from '~/components/AlertWithButton'
8+
9+
export default function Maps(props: {
10+
maps: { baseAssetsExist: boolean; regionFiles: FileEntry[] }
11+
}) {
12+
const alertMessage = !props.maps.baseAssetsExist
13+
? 'The base map assets have not been installed. Please download them first to enable map functionality.'
14+
: props.maps.regionFiles.length === 0
15+
? 'No map regions have been downloaded yet. Please download some regions to enable map functionality.'
16+
: null
617

7-
export default function Maps() {
818
return (
919
<MapsLayout>
1020
<Head title="Maps" />
@@ -19,7 +29,23 @@ export default function Maps() {
1929
</StyledButton>
2030
</Link>
2131
</div>
22-
<div className="w-full h-full flex p-4 justify-center items-center">
32+
<div className="w-full min-h-screen flex flex-col items-center justify-center py-4 mx-4">
33+
{alertMessage && (
34+
<AlertWithButton
35+
title={alertMessage}
36+
type="warning"
37+
variant="solid"
38+
className="w-full !mb-4"
39+
buttonProps={{
40+
variant: 'secondary',
41+
children: 'Go to Map Settings',
42+
icon: 'Cog6ToothIcon',
43+
onClick: () => {
44+
window.location.href = '/settings/maps'
45+
},
46+
}}
47+
/>
48+
)}
2349
<MapComponent />
2450
</div>
2551
</MapsLayout>

admin/inertia/pages/settings/maps.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import StyledButton from '~/components/StyledButton'
55
import { useModals } from '~/context/ModalContext'
66
import StyledModal from '~/components/StyledModal'
77
import { FileEntry } from '../../../types/files'
8-
import MissingBaseAssetsAlert from '~/components/layout/MissingBaseAssetsAlert'
98
import { useNotifications } from '~/context/NotificationContext'
109
import { useState } from 'react'
1110
import api from '~/lib/api'
@@ -16,6 +15,7 @@ import StyledSectionHeader from '~/components/StyledSectionHeader'
1615
import CuratedCollectionCard from '~/components/CuratedCollectionCard'
1716
import { CuratedCollectionWithStatus } from '../../../types/downloads'
1817
import ActiveDownloads from '~/components/ActiveDownloads'
18+
import AlertWithButton from '~/components/AlertWithButton'
1919

2020
const CURATED_COLLECTIONS_KEY = 'curated-map-collections'
2121

@@ -194,7 +194,19 @@ export default function MapsManager(props: {
194194
</div>
195195
</div>
196196
{!props.maps.baseAssetsExist && (
197-
<MissingBaseAssetsAlert loading={downloading} onClickDownload={downloadBaseAssets} />
197+
<AlertWithButton
198+
title="The base map assets have not been installed. Please download them first to enable map functionality."
199+
type="warning"
200+
variant="solid"
201+
className="my-4"
202+
buttonProps={{
203+
variant: 'secondary',
204+
children: 'Download Base Assets',
205+
icon: 'ArrowDownTrayIcon',
206+
loading: downloading,
207+
onClick: () => downloadBaseAssets(),
208+
}}
209+
/>
198210
)}
199211
<StyledSectionHeader title="Curated Map Collections" className="mt-8 !mb-4" />
200212
<StyledButton

admin/inertia/pages/settings/zim/remote-explorer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ export default function ZimRemoteExplorer() {
6666
const pageParsed = parseInt((pageParam as number).toString(), 10)
6767
const start = isNaN(pageParsed) ? 0 : pageParsed * 12
6868
const res = await api.listRemoteZimFiles({ start, count: 12, query: query || undefined })
69+
if (!res) {
70+
throw new Error('Failed to fetch remote ZIM files.')
71+
}
6972
return res.data
7073
},
7174
initialPageParam: 0,

0 commit comments

Comments
 (0)