-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
201 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { deleteImagesTask, fetchTask, selectDeleteImagesLoading } from '../tasks/tasksSlice.js'; | ||
import { selectActiveFilters } from '../filters/filtersSlice.js'; | ||
import { SimpleSpinner, SpinnerOverlay } from '../../components/Spinner'; | ||
import { ButtonRow, HelperText } from '../../components/Form'; | ||
import Button from '../../components/Button'; | ||
import NoneFoundAlert from '../../components/NoneFoundAlert'; | ||
import { fetchImagesCount, fetchImages, deleteImages } from './imagesSlice.js'; | ||
|
||
const DeleteImagesModal = async () => { | ||
const filters = useSelector(selectActiveFilters); | ||
const deleteImagesLoading = useSelector(selectDeleteImagesLoading); | ||
const dispatch = useDispatch(); | ||
|
||
const imageCount = await dispatch(fetchImagesCount(filters)); | ||
|
||
const deleteImagesPending = deleteImagesLoading.isLoading && deleteImagesLoading.taskId; | ||
useEffect(() => { | ||
if (deleteImagesPending) { | ||
dispatch(fetchTask(deleteImagesLoading.taskId)); | ||
} | ||
}, [deleteImagesPending, deleteImagesLoading, dispatch]); | ||
|
||
const handleDeleteImagesButtonClick = () => { | ||
const { isLoading, errors, noneFound } = deleteImagesLoading; | ||
const noErrors = !errors || errors.length === 0; | ||
if (!noneFound && !isLoading && noErrors) { | ||
// const images = dispatch(fetchImages(filters)); | ||
if (imageCount > 50) { | ||
dispatch(deleteImagesTask({ filters })); | ||
} else { | ||
dispatch(fetchImages(filters)).then((images) => { | ||
dispatch(deleteImages({ images })); | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
{deleteImagesLoading.isLoading && ( | ||
<SpinnerOverlay> | ||
<SimpleSpinner /> | ||
</SpinnerOverlay> | ||
)} | ||
{imageCount === 0 && ( | ||
<NoneFoundAlert> | ||
We couldn't find any images that matched this set of filters. | ||
</NoneFoundAlert> | ||
)} | ||
<HelperText> | ||
<p> | ||
Do you wish to delete all images that match the current filters? This action will delete | ||
{imageCount} images and cannot be undone. | ||
</p> | ||
</HelperText> | ||
<ButtonRow> | ||
<Button | ||
type="submit" | ||
size="large" | ||
disabled={deleteImagesLoading.isLoading} | ||
data-format="coco" | ||
onClick={handleDeleteImagesButtonClick} | ||
> | ||
Delete Images | ||
</Button> | ||
</ButtonRow> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DeleteImagesModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters