diff --git a/admin/inertia/components/DownloadURLModal.tsx b/admin/inertia/components/DownloadURLModal.tsx index 4bba80b..ed39793 100644 --- a/admin/inertia/components/DownloadURLModal.tsx +++ b/admin/inertia/components/DownloadURLModal.tsx @@ -16,14 +16,19 @@ const DownloadURLModal: React.FC = ({ onPreflightSuccess, ...modalProps }) => { - const [url, setUrl] = useState(suggestedURL || '') + const [url, setUrl] = useState('') const [messages, setMessages] = useState([]) - const [passedPreflight, setPassedPreflight] = useState(false) + const [loading, setLoading] = useState(false) async function runPreflightCheck(downloadUrl: string) { try { + setLoading(true) setMessages([`Running preflight check for URL: ${downloadUrl}`]) const res = await api.downloadRemoteMapRegionPreflight(downloadUrl) + if (!res) { + throw new Error('An unknown error occurred during the preflight check.') + } + if ('message' in res) { throw new Error(res.message) } @@ -32,11 +37,15 @@ const DownloadURLModal: React.FC = ({ ...prev, `Preflight check passed. Filename: ${res.filename}, Size: ${(res.size / (1024 * 1024)).toFixed(2)} MB`, ]) - setPassedPreflight(true) + + if (onPreflightSuccess) { + onPreflightSuccess(downloadUrl) + } } catch (error) { console.error('Preflight check failed:', error) setMessages((prev) => [...prev, `Preflight check failed: ${error.message}`]) - setPassedPreflight(false) + } finally { + setLoading(false) } } @@ -49,6 +58,8 @@ const DownloadURLModal: React.FC = ({ confirmIcon="ArrowDownTrayIcon" cancelText="Cancel" confirmVariant="primary" + confirmLoading={loading} + cancelLoading={loading} large >
diff --git a/admin/inertia/components/MarkdocRenderer.tsx b/admin/inertia/components/MarkdocRenderer.tsx index db1d543..bab0917 100644 --- a/admin/inertia/components/MarkdocRenderer.tsx +++ b/admin/inertia/components/MarkdocRenderer.tsx @@ -43,8 +43,6 @@ interface MarkdocRendererProps { } const MarkdocRenderer: React.FC = ({ content }) => { - console.log('Markdoc content:', content) - return
{Markdoc.renderers.react(content, React, { components })}
} diff --git a/admin/inertia/components/StyledModal.tsx b/admin/inertia/components/StyledModal.tsx index dd4ad6e..fed08c1 100644 --- a/admin/inertia/components/StyledModal.tsx +++ b/admin/inertia/components/StyledModal.tsx @@ -8,9 +8,11 @@ export type StyledModalProps = { title: string cancelText?: string cancelIcon?: StyledButtonProps['icon'] + cancelLoading?: boolean confirmText?: string confirmIcon?: StyledButtonProps['icon'] confirmVariant?: StyledButtonProps['variant'] + confirmLoading?: boolean open: boolean onCancel?: () => void onConfirm?: () => void @@ -26,9 +28,11 @@ const StyledModal: React.FC = ({ onClose, cancelText = 'Cancel', cancelIcon, + cancelLoading = false, confirmText = 'Confirm', confirmIcon, confirmVariant = 'action', + confirmLoading = false, onCancel, onConfirm, icon, @@ -77,6 +81,7 @@ const StyledModal: React.FC = ({ if (onCancel) onCancel() }} icon={cancelIcon} + loading={cancelLoading} > {cancelText} @@ -88,6 +93,7 @@ const StyledModal: React.FC = ({ if (onConfirm) onConfirm() }} icon={confirmIcon} + loading={confirmLoading} > {confirmText} diff --git a/admin/inertia/pages/settings/maps.tsx b/admin/inertia/pages/settings/maps.tsx index 49be5b4..8f57cbe 100644 --- a/admin/inertia/pages/settings/maps.tsx +++ b/admin/inertia/pages/settings/maps.tsx @@ -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) { try { await api.downloadMapCollection(record.slug) invalidateDownloads() + addNotification({ + type: 'success', + message: `Download for collection "${record.name}" has been queued.`, + }) } catch (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) { openModal( closeAllModals()} + onPreflightSuccess={async (url) => { + await downloadCustomFile(url) + closeAllModals() + }} />, 'download-map-file-modal' )