import { useState } from 'react' import StyledModal, { StyledModalProps } from './StyledModal' import Input from './inputs/Input' import api from '~/lib/api' export type DownloadURLModalProps = Omit< StyledModalProps, 'onConfirm' | 'open' | 'confirmText' | 'cancelText' | 'confirmVariant' | 'children' > & { suggestedURL?: string onPreflightSuccess?: (url: string) => void } const DownloadURLModal: React.FC = ({ suggestedURL, onPreflightSuccess, ...modalProps }) => { const [url, setUrl] = useState(suggestedURL || '') const [messages, setMessages] = useState([]) const [passedPreflight, setPassedPreflight] = useState(false) async function runPreflightCheck(downloadUrl: string) { try { setMessages([`Running preflight check for URL: ${downloadUrl}`]) const res = await api.downloadRemoteMapRegionPreflight(downloadUrl) if ('message' in res) { throw new Error(res.message) } setMessages((prev) => [ ...prev, `Preflight check passed. Filename: ${res.filename}, Size: ${(res.size / (1024 * 1024)).toFixed(2)} MB`, ]) setPassedPreflight(true) } catch (error) { console.error('Preflight check failed:', error) setMessages((prev) => [...prev, `Preflight check failed: ${error.message}`]) setPassedPreflight(false) } } return ( runPreflightCheck(url)} open={true} confirmText="Download" confirmIcon="ArrowDownTrayIcon" cancelText="Cancel" confirmVariant="primary" large >

Enter the URL of the map region file you wish to download. The URL must be publicly reachable and end with .pmtiles. A preflight check will be run to verify the file's availability, type, and approximate size.

setUrl(e.target.value)} />
{messages.map((message, idx) => (

{message}

))}
) } export default DownloadURLModal