Project NOMAD is an offline-first knowledge and education server. Wikipedia, thousands of books, courses, maps, and optional local AI, all running on hardware you own with no internet required.
TypeScript
fix(UI): wire map file delete confirmation to API (#732)
cuyua9e561ce84d104
diff --git a/admin/inertia/lib/api.ts b/admin/inertia/lib/api.tsindex 0df95ae0..2449259d 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.tsxindex da97bb1f..47055fa7 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<string | null>(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(<StyledModaltitle="Confirm Delete?"- onConfirm={() => {- closeAllModals()- }}+ onConfirm={() => deleteFile(file)}onCancel={closeAllModals}open={true}confirmText="Delete"cancelText="Cancel"confirmVariant="danger"+ confirmLoading={file.type === 'file' && deletingFileKey === file.key}><p className="text-text-secondary">Are you sure you want to delete {file.name}? This action cannot be undone.