mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-04-05 16:26:15 +02:00
fix(Maps): custom pmtiles file downloads
This commit is contained in:
parent
0d13ff7bac
commit
b020d925ad
|
|
@ -16,14 +16,19 @@ const DownloadURLModal: React.FC<DownloadURLModalProps> = ({
|
||||||
onPreflightSuccess,
|
onPreflightSuccess,
|
||||||
...modalProps
|
...modalProps
|
||||||
}) => {
|
}) => {
|
||||||
const [url, setUrl] = useState<string>(suggestedURL || '')
|
const [url, setUrl] = useState<string>('')
|
||||||
const [messages, setMessages] = useState<string[]>([])
|
const [messages, setMessages] = useState<string[]>([])
|
||||||
const [passedPreflight, setPassedPreflight] = useState<boolean>(false)
|
const [loading, setLoading] = useState<boolean>(false)
|
||||||
|
|
||||||
async function runPreflightCheck(downloadUrl: string) {
|
async function runPreflightCheck(downloadUrl: string) {
|
||||||
try {
|
try {
|
||||||
|
setLoading(true)
|
||||||
setMessages([`Running preflight check for URL: ${downloadUrl}`])
|
setMessages([`Running preflight check for URL: ${downloadUrl}`])
|
||||||
const res = await api.downloadRemoteMapRegionPreflight(downloadUrl)
|
const res = await api.downloadRemoteMapRegionPreflight(downloadUrl)
|
||||||
|
if (!res) {
|
||||||
|
throw new Error('An unknown error occurred during the preflight check.')
|
||||||
|
}
|
||||||
|
|
||||||
if ('message' in res) {
|
if ('message' in res) {
|
||||||
throw new Error(res.message)
|
throw new Error(res.message)
|
||||||
}
|
}
|
||||||
|
|
@ -32,11 +37,15 @@ const DownloadURLModal: React.FC<DownloadURLModalProps> = ({
|
||||||
...prev,
|
...prev,
|
||||||
`Preflight check passed. Filename: ${res.filename}, Size: ${(res.size / (1024 * 1024)).toFixed(2)} MB`,
|
`Preflight check passed. Filename: ${res.filename}, Size: ${(res.size / (1024 * 1024)).toFixed(2)} MB`,
|
||||||
])
|
])
|
||||||
setPassedPreflight(true)
|
|
||||||
|
if (onPreflightSuccess) {
|
||||||
|
onPreflightSuccess(downloadUrl)
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Preflight check failed:', error)
|
console.error('Preflight check failed:', error)
|
||||||
setMessages((prev) => [...prev, `Preflight check failed: ${error.message}`])
|
setMessages((prev) => [...prev, `Preflight check failed: ${error.message}`])
|
||||||
setPassedPreflight(false)
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,6 +58,8 @@ const DownloadURLModal: React.FC<DownloadURLModalProps> = ({
|
||||||
confirmIcon="ArrowDownTrayIcon"
|
confirmIcon="ArrowDownTrayIcon"
|
||||||
cancelText="Cancel"
|
cancelText="Cancel"
|
||||||
confirmVariant="primary"
|
confirmVariant="primary"
|
||||||
|
confirmLoading={loading}
|
||||||
|
cancelLoading={loading}
|
||||||
large
|
large
|
||||||
>
|
>
|
||||||
<div className="flex flex-col pb-4">
|
<div className="flex flex-col pb-4">
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,6 @@ interface MarkdocRendererProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
const MarkdocRenderer: React.FC<MarkdocRendererProps> = ({ content }) => {
|
const MarkdocRenderer: React.FC<MarkdocRendererProps> = ({ content }) => {
|
||||||
console.log('Markdoc content:', content)
|
|
||||||
|
|
||||||
return <div className="tracking-wide">{Markdoc.renderers.react(content, React, { components })}</div>
|
return <div className="tracking-wide">{Markdoc.renderers.react(content, React, { components })}</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,11 @@ export type StyledModalProps = {
|
||||||
title: string
|
title: string
|
||||||
cancelText?: string
|
cancelText?: string
|
||||||
cancelIcon?: StyledButtonProps['icon']
|
cancelIcon?: StyledButtonProps['icon']
|
||||||
|
cancelLoading?: boolean
|
||||||
confirmText?: string
|
confirmText?: string
|
||||||
confirmIcon?: StyledButtonProps['icon']
|
confirmIcon?: StyledButtonProps['icon']
|
||||||
confirmVariant?: StyledButtonProps['variant']
|
confirmVariant?: StyledButtonProps['variant']
|
||||||
|
confirmLoading?: boolean
|
||||||
open: boolean
|
open: boolean
|
||||||
onCancel?: () => void
|
onCancel?: () => void
|
||||||
onConfirm?: () => void
|
onConfirm?: () => void
|
||||||
|
|
@ -26,9 +28,11 @@ const StyledModal: React.FC<StyledModalProps> = ({
|
||||||
onClose,
|
onClose,
|
||||||
cancelText = 'Cancel',
|
cancelText = 'Cancel',
|
||||||
cancelIcon,
|
cancelIcon,
|
||||||
|
cancelLoading = false,
|
||||||
confirmText = 'Confirm',
|
confirmText = 'Confirm',
|
||||||
confirmIcon,
|
confirmIcon,
|
||||||
confirmVariant = 'action',
|
confirmVariant = 'action',
|
||||||
|
confirmLoading = false,
|
||||||
onCancel,
|
onCancel,
|
||||||
onConfirm,
|
onConfirm,
|
||||||
icon,
|
icon,
|
||||||
|
|
@ -77,6 +81,7 @@ const StyledModal: React.FC<StyledModalProps> = ({
|
||||||
if (onCancel) onCancel()
|
if (onCancel) onCancel()
|
||||||
}}
|
}}
|
||||||
icon={cancelIcon}
|
icon={cancelIcon}
|
||||||
|
loading={cancelLoading}
|
||||||
>
|
>
|
||||||
{cancelText}
|
{cancelText}
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
|
|
@ -88,6 +93,7 @@ const StyledModal: React.FC<StyledModalProps> = ({
|
||||||
if (onConfirm) onConfirm()
|
if (onConfirm) onConfirm()
|
||||||
}}
|
}}
|
||||||
icon={confirmIcon}
|
icon={confirmIcon}
|
||||||
|
loading={confirmLoading}
|
||||||
>
|
>
|
||||||
{confirmText}
|
{confirmText}
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
|
|
|
||||||
|
|
@ -66,24 +66,32 @@ export default function MapsManager(props: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadFile(record: string) {
|
|
||||||
try {
|
|
||||||
//await api.downloadRemoteZimFile(record.download_url)
|
|
||||||
invalidateDownloads()
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error downloading file:', error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function downloadCollection(record: CuratedCollectionWithStatus) {
|
async function downloadCollection(record: CuratedCollectionWithStatus) {
|
||||||
try {
|
try {
|
||||||
await api.downloadMapCollection(record.slug)
|
await api.downloadMapCollection(record.slug)
|
||||||
invalidateDownloads()
|
invalidateDownloads()
|
||||||
|
addNotification({
|
||||||
|
type: 'success',
|
||||||
|
message: `Download for collection "${record.name}" has been queued.`,
|
||||||
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error downloading collection:', error)
|
console.error('Error downloading collection:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function downloadCustomFile(url: string) {
|
||||||
|
try {
|
||||||
|
await api.downloadRemoteMapRegion(url)
|
||||||
|
invalidateDownloads()
|
||||||
|
addNotification({
|
||||||
|
type: 'success',
|
||||||
|
message: 'Download has been queued.',
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error downloading custom file:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function confirmDeleteFile(file: FileEntry) {
|
async function confirmDeleteFile(file: FileEntry) {
|
||||||
openModal(
|
openModal(
|
||||||
<StyledModal
|
<StyledModal
|
||||||
|
|
@ -120,8 +128,6 @@ export default function MapsManager(props: {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
downloadCollection(record)
|
downloadCollection(record)
|
||||||
} else {
|
|
||||||
downloadFile(record)
|
|
||||||
}
|
}
|
||||||
closeAllModals()
|
closeAllModals()
|
||||||
}}
|
}}
|
||||||
|
|
@ -145,8 +151,12 @@ export default function MapsManager(props: {
|
||||||
openModal(
|
openModal(
|
||||||
<DownloadURLModal
|
<DownloadURLModal
|
||||||
title="Download Map File"
|
title="Download Map File"
|
||||||
suggestedURL="https://github.com/Crosstalk-Solutions/project-nomad-maps/raw/refs/heads/master/"
|
suggestedURL="e.g. https://github.com/Crosstalk-Solutions/project-nomad-maps/raw/refs/heads/master/pmtiles/california.pmtiles"
|
||||||
onCancel={() => closeAllModals()}
|
onCancel={() => closeAllModals()}
|
||||||
|
onPreflightSuccess={async (url) => {
|
||||||
|
await downloadCustomFile(url)
|
||||||
|
closeAllModals()
|
||||||
|
}}
|
||||||
/>,
|
/>,
|
||||||
'download-map-file-modal'
|
'download-map-file-modal'
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user