mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-05-30 16:16:50 +02:00
fix(UI): wire map file delete confirmation to API (#732)
Co-authored-by: cuyua9 <cuyua9@users.noreply.github.com>
This commit is contained in:
parent
10df90d757
commit
e561ce84d1
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
<StyledModal
|
||||
title="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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user