Fix multi-photo delete loading status

This commit is contained in:
Sam Becker 2024-07-21 10:58:18 -05:00
parent b71a3825db
commit 94585b4a7f
2 changed files with 11 additions and 1 deletions

View File

@ -100,7 +100,9 @@ export default function AdminBatchEditPanelClient({
<DeletePhotosButton
photoIds={selectedPhotoIds}
disabled={isPerformingSelectEdit}
onClick={() => setIsPerformingSelectEdit?.(true)}
onDelete={resetForm}
onFinish={() => setIsPerformingSelectEdit?.(false)}
/>
</>}
<LoaderButton

View File

@ -14,11 +14,15 @@ export default function DeletePhotosButton({
onDelete,
clearLocalState = true,
className,
onClick,
onFinish,
confirmText,
toastText,
...rest
}: {
photoIds?: string[]
onClick?: () => void
onFinish?: () => void
onDelete?: () => void
clearLocalState?: boolean
toastText?: string
@ -47,6 +51,7 @@ export default function DeletePhotosButton({
// eslint-disable-next-line max-len
confirmText={confirmText ?? `Are you sure you want to delete ${photosText}? This action cannot be undone.`}
onClick={() => {
onClick?.();
setIsLoading(true);
deletePhotosAction(photoIds)
.then(() => {
@ -58,7 +63,10 @@ export default function DeletePhotosButton({
onDelete?.();
})
.catch(() => toastWarning(`Failed to delete ${photosText}`))
.finally(() => setIsLoading(false));
.finally(() => {
setIsLoading(false);
onFinish?.();
});
}}
/>
);