Skip to content

Commit b020d92

Browse files
committed
fix(Maps): custom pmtiles file downloads
1 parent 0d13ff7 commit b020d92

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

admin/inertia/components/DownloadURLModal.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ const DownloadURLModal: React.FC<DownloadURLModalProps> = ({
1616
onPreflightSuccess,
1717
...modalProps
1818
}) => {
19-
const [url, setUrl] = useState<string>(suggestedURL || '')
19+
const [url, setUrl] = useState<string>('')
2020
const [messages, setMessages] = useState<string[]>([])
21-
const [passedPreflight, setPassedPreflight] = useState<boolean>(false)
21+
const [loading, setLoading] = useState<boolean>(false)
2222

2323
async function runPreflightCheck(downloadUrl: string) {
2424
try {
25+
setLoading(true)
2526
setMessages([`Running preflight check for URL: ${downloadUrl}`])
2627
const res = await api.downloadRemoteMapRegionPreflight(downloadUrl)
28+
if (!res) {
29+
throw new Error('An unknown error occurred during the preflight check.')
30+
}
31+
2732
if ('message' in res) {
2833
throw new Error(res.message)
2934
}
@@ -32,11 +37,15 @@ const DownloadURLModal: React.FC<DownloadURLModalProps> = ({
3237
...prev,
3338
`Preflight check passed. Filename: ${res.filename}, Size: ${(res.size / (1024 * 1024)).toFixed(2)} MB`,
3439
])
35-
setPassedPreflight(true)
40+
41+
if (onPreflightSuccess) {
42+
onPreflightSuccess(downloadUrl)
43+
}
3644
} catch (error) {
3745
console.error('Preflight check failed:', error)
3846
setMessages((prev) => [...prev, `Preflight check failed: ${error.message}`])
39-
setPassedPreflight(false)
47+
} finally {
48+
setLoading(false)
4049
}
4150
}
4251

@@ -49,6 +58,8 @@ const DownloadURLModal: React.FC<DownloadURLModalProps> = ({
4958
confirmIcon="ArrowDownTrayIcon"
5059
cancelText="Cancel"
5160
confirmVariant="primary"
61+
confirmLoading={loading}
62+
cancelLoading={loading}
5263
large
5364
>
5465
<div className="flex flex-col pb-4">

admin/inertia/components/MarkdocRenderer.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ interface MarkdocRendererProps {
4343
}
4444

4545
const MarkdocRenderer: React.FC<MarkdocRendererProps> = ({ content }) => {
46-
console.log('Markdoc content:', content)
47-
4846
return <div className="tracking-wide">{Markdoc.renderers.react(content, React, { components })}</div>
4947
}
5048

admin/inertia/components/StyledModal.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ export type StyledModalProps = {
88
title: string
99
cancelText?: string
1010
cancelIcon?: StyledButtonProps['icon']
11+
cancelLoading?: boolean
1112
confirmText?: string
1213
confirmIcon?: StyledButtonProps['icon']
1314
confirmVariant?: StyledButtonProps['variant']
15+
confirmLoading?: boolean
1416
open: boolean
1517
onCancel?: () => void
1618
onConfirm?: () => void
@@ -26,9 +28,11 @@ const StyledModal: React.FC<StyledModalProps> = ({
2628
onClose,
2729
cancelText = 'Cancel',
2830
cancelIcon,
31+
cancelLoading = false,
2932
confirmText = 'Confirm',
3033
confirmIcon,
3134
confirmVariant = 'action',
35+
confirmLoading = false,
3236
onCancel,
3337
onConfirm,
3438
icon,
@@ -77,6 +81,7 @@ const StyledModal: React.FC<StyledModalProps> = ({
7781
if (onCancel) onCancel()
7882
}}
7983
icon={cancelIcon}
84+
loading={cancelLoading}
8085
>
8186
{cancelText}
8287
</StyledButton>
@@ -88,6 +93,7 @@ const StyledModal: React.FC<StyledModalProps> = ({
8893
if (onConfirm) onConfirm()
8994
}}
9095
icon={confirmIcon}
96+
loading={confirmLoading}
9197
>
9298
{confirmText}
9399
</StyledButton>

admin/inertia/pages/settings/maps.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,29 @@ export default function MapsManager(props: {
6666
}
6767
}
6868

69-
async function downloadFile(record: string) {
69+
async function downloadCollection(record: CuratedCollectionWithStatus) {
7070
try {
71-
//await api.downloadRemoteZimFile(record.download_url)
71+
await api.downloadMapCollection(record.slug)
7272
invalidateDownloads()
73+
addNotification({
74+
type: 'success',
75+
message: `Download for collection "${record.name}" has been queued.`,
76+
})
7377
} catch (error) {
74-
console.error('Error downloading file:', error)
78+
console.error('Error downloading collection:', error)
7579
}
7680
}
7781

78-
async function downloadCollection(record: CuratedCollectionWithStatus) {
82+
async function downloadCustomFile(url: string) {
7983
try {
80-
await api.downloadMapCollection(record.slug)
84+
await api.downloadRemoteMapRegion(url)
8185
invalidateDownloads()
86+
addNotification({
87+
type: 'success',
88+
message: 'Download has been queued.',
89+
})
8290
} catch (error) {
83-
console.error('Error downloading collection:', error)
91+
console.error('Error downloading custom file:', error)
8492
}
8593
}
8694

@@ -120,8 +128,6 @@ export default function MapsManager(props: {
120128
return
121129
}
122130
downloadCollection(record)
123-
} else {
124-
downloadFile(record)
125131
}
126132
closeAllModals()
127133
}}
@@ -145,8 +151,12 @@ export default function MapsManager(props: {
145151
openModal(
146152
<DownloadURLModal
147153
title="Download Map File"
148-
suggestedURL="https://github.com/Crosstalk-Solutions/project-nomad-maps/raw/refs/heads/master/"
154+
suggestedURL="e.g. https://github.com/Crosstalk-Solutions/project-nomad-maps/raw/refs/heads/master/pmtiles/california.pmtiles"
149155
onCancel={() => closeAllModals()}
156+
onPreflightSuccess={async (url) => {
157+
await downloadCustomFile(url)
158+
closeAllModals()
159+
}}
150160
/>,
151161
'download-map-file-modal'
152162
)

0 commit comments

Comments
 (0)