diff --git a/admin/inertia/lib/api.ts b/admin/inertia/lib/api.ts index 0df95ae..2449259 100644 --- a/admin/inertia/lib/api.ts +++ b/admin/inertia/lib/api.ts @@ -130,6 +130,15 @@ class API { })() } + async deleteMapRegionFile(filename: string): Promise<{ message: string }> { + return catchInternal(async () => { + const response = await this.client.delete<{ message: string }>( + `/maps/${encodeURIComponent(filename)}` + ) + return response.data + })() + } + async downloadRemoteZimFile( url: string, metadata?: { title: string; summary?: string; author?: string; size_bytes?: number } diff --git a/admin/inertia/pages/settings/maps.tsx b/admin/inertia/pages/settings/maps.tsx index da97bb1..47055fa 100644 --- a/admin/inertia/pages/settings/maps.tsx +++ b/admin/inertia/pages/settings/maps.tsx @@ -29,6 +29,7 @@ export default function MapsManager(props: { const { openModal, closeAllModals } = useModals() const { addNotification } = useNotifications() const [downloading, setDownloading] = useState(false) + const [deletingFileKey, setDeletingFileKey] = useState(null) const { data: curatedCollections } = useQuery({ queryKey: [CURATED_COLLECTIONS_KEY], @@ -120,18 +121,40 @@ export default function MapsManager(props: { } } + async function deleteFile(file: FileEntry) { + if (file.type !== 'file') return + + try { + setDeletingFileKey(file.key) + await api.deleteMapRegionFile(file.key) + addNotification({ + type: 'success', + message: `${file.name} has been deleted.`, + }) + closeAllModals() + router.reload({ only: ['maps'] }) + } catch (error) { + console.error('Error deleting map file:', error) + addNotification({ + type: 'error', + message: `Failed to delete ${file.name}. Please try again.`, + }) + } finally { + setDeletingFileKey(null) + } + } + async function confirmDeleteFile(file: FileEntry) { openModal( { - closeAllModals() - }} + onConfirm={() => deleteFile(file)} onCancel={closeAllModals} open={true} confirmText="Delete" cancelText="Cancel" confirmVariant="danger" + confirmLoading={file.type === 'file' && deletingFileKey === file.key} >

Are you sure you want to delete {file.name}? This action cannot be undone.