fix(UI): wire map file delete confirmation to API (#732)

Co-authored-by: cuyua9 <cuyua9@users.noreply.github.com>
This commit is contained in:
cuyua9 2026-05-04 03:49:06 +08:00 committed by Jake Turner
parent 10df90d757
commit e561ce84d1
2 changed files with 35 additions and 3 deletions

View File

@ -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( async downloadRemoteZimFile(
url: string, url: string,
metadata?: { title: string; summary?: string; author?: string; size_bytes?: number } metadata?: { title: string; summary?: string; author?: string; size_bytes?: number }

View File

@ -29,6 +29,7 @@ export default function MapsManager(props: {
const { openModal, closeAllModals } = useModals() const { openModal, closeAllModals } = useModals()
const { addNotification } = useNotifications() const { addNotification } = useNotifications()
const [downloading, setDownloading] = useState(false) const [downloading, setDownloading] = useState(false)
const [deletingFileKey, setDeletingFileKey] = useState<string | null>(null)
const { data: curatedCollections } = useQuery({ const { data: curatedCollections } = useQuery({
queryKey: [CURATED_COLLECTIONS_KEY], 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) { async function confirmDeleteFile(file: FileEntry) {
openModal( openModal(
<StyledModal <StyledModal
title="Confirm Delete?" title="Confirm Delete?"
onConfirm={() => { onConfirm={() => deleteFile(file)}
closeAllModals()
}}
onCancel={closeAllModals} onCancel={closeAllModals}
open={true} open={true}
confirmText="Delete" confirmText="Delete"
cancelText="Cancel" cancelText="Cancel"
confirmVariant="danger" confirmVariant="danger"
confirmLoading={file.type === 'file' && deletingFileKey === file.key}
> >
<p className="text-text-secondary"> <p className="text-text-secondary">
Are you sure you want to delete {file.name}? This action cannot be undone. Are you sure you want to delete {file.name}? This action cannot be undone.