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 <DeletePhotosButton
photoIds={selectedPhotoIds} photoIds={selectedPhotoIds}
disabled={isPerformingSelectEdit} disabled={isPerformingSelectEdit}
onClick={() => setIsPerformingSelectEdit?.(true)}
onDelete={resetForm} onDelete={resetForm}
onFinish={() => setIsPerformingSelectEdit?.(false)}
/> />
</>} </>}
<LoaderButton <LoaderButton

View File

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