Skip to content

Commit c2479cc

Browse files
authored
No pop up message when removing media from albums #215 (#24)
* No pop up message when removing media from albums #215 * Fix typo * fix another typo
1 parent faf036d commit c2479cc

File tree

1 file changed

+87
-25
lines changed

1 file changed

+87
-25
lines changed

src/components/ImageGallery.tsx

Lines changed: 87 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ import {
2525
useMutation,
2626
useQueryClient,
2727
} from '@tanstack/react-query';
28-
import { addObjectsToAlbum, bulkRemoveObjectsFromAlbum, getAlbumItems } from 'api/albumApi';
28+
import {
29+
addObjectsToAlbum,
30+
bulkRemoveObjectsFromAlbum,
31+
getAlbumItems,
32+
} from 'api/albumApi';
2933
import React, { useEffect, useState } from 'react';
3034
import toast from 'react-hot-toast';
3135
import { useInView } from 'react-intersection-observer';
@@ -110,10 +114,14 @@ export const ImageGallery: React.FC<{ albumId?: string }> = ({ albumId }) => {
110114
toast.success('The file(s) were added to the selected album(s).');
111115
setSelectedImages([]);
112116
setOpenAddToAlbumDialog(false);
113-
queryClient.invalidateQueries({ queryKey: ['fetchIds', albumId ?? null] });
117+
queryClient.invalidateQueries({
118+
queryKey: ['fetchIds', albumId ?? null],
119+
});
114120
},
115121
onError: (error) => {
116-
toast.error(`Error adding object to the album: ${error?.message ?? 'Error'}`);
122+
toast.error(
123+
`Error adding object to the album: ${error?.message ?? 'Error'}`
124+
);
117125
},
118126
});
119127

@@ -122,7 +130,9 @@ export const ImageGallery: React.FC<{ albumId?: string }> = ({ albumId }) => {
122130
onSuccess: () => {
123131
toast.success('Selected item(s) were removed from the album.');
124132
setSelectedImages([]);
125-
queryClient.invalidateQueries({ queryKey: ['fetchIds', albumId ?? null] });
133+
queryClient.invalidateQueries({
134+
queryKey: ['fetchIds', albumId ?? null],
135+
});
126136
},
127137
onError: (error) => {
128138
toast.error(`Error removing from album: ${error?.message ?? 'Error'}`);
@@ -187,7 +197,9 @@ export const ImageGallery: React.FC<{ albumId?: string }> = ({ albumId }) => {
187197
{
188198
onSuccess: () => {
189199
handleClearSelection();
190-
queryClient.invalidateQueries({ queryKey: ['fetchIds', albumId ?? null] });
200+
queryClient.invalidateQueries({
201+
queryKey: ['fetchIds', albumId ?? null],
202+
});
191203
},
192204
}
193205
);
@@ -203,8 +215,7 @@ export const ImageGallery: React.FC<{ albumId?: string }> = ({ albumId }) => {
203215
const match = disposition.match(
204216
/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
205217
);
206-
if (match && match[1])
207-
filename = match[1].replace(/['"]/g, '');
218+
if (match && match[1]) filename = match[1].replace(/['"]/g, '');
208219
}
209220

210221
const link = document.createElement('a');
@@ -224,7 +235,9 @@ export const ImageGallery: React.FC<{ albumId?: string }> = ({ albumId }) => {
224235
{
225236
onSuccess: () => {
226237
handleClearSelection();
227-
queryClient.invalidateQueries({ queryKey: ['fetchIds', albumId ?? null] });
238+
queryClient.invalidateQueries({
239+
queryKey: ['fetchIds', albumId ?? null],
240+
});
228241
},
229242
}
230243
);
@@ -235,7 +248,9 @@ export const ImageGallery: React.FC<{ albumId?: string }> = ({ albumId }) => {
235248
{ objectIds: [id] },
236249
{
237250
onSuccess: () => {
238-
queryClient.invalidateQueries({ queryKey: ['fetchIds', albumId ?? null] });
251+
queryClient.invalidateQueries({
252+
queryKey: ['fetchIds', albumId ?? null],
253+
});
239254
},
240255
}
241256
);
@@ -246,7 +261,9 @@ export const ImageGallery: React.FC<{ albumId?: string }> = ({ albumId }) => {
246261
{ objectIds: [id] },
247262
{
248263
onSuccess: () => {
249-
queryClient.invalidateQueries({ queryKey: ['fetchIds', albumId ?? null] });
264+
queryClient.invalidateQueries({
265+
queryKey: ['fetchIds', albumId ?? null],
266+
});
250267
},
251268
}
252269
);
@@ -255,11 +272,16 @@ export const ImageGallery: React.FC<{ albumId?: string }> = ({ albumId }) => {
255272

256273
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
257274

275+
const [openRemoveFromAlbumDialog, setOpenRemoveFromAlbumDialog] = useState(false);
276+
258277
const [openAddToAlbumDialog, setOpenAddToAlbumDialog] = React.useState(false);
259278

260279
const handleAddToAlbum = (albumIdToAdd: string) => {
261280
if (selectedImages.length === 0) return;
262-
addToAlbumMutation.mutate({ albumId: albumIdToAdd, objectIds: selectedImages });
281+
addToAlbumMutation.mutate({
282+
albumId: albumIdToAdd,
283+
objectIds: selectedImages,
284+
});
263285
};
264286

265287
const handleRemoveFromAlbum = () => {
@@ -311,18 +333,60 @@ export const ImageGallery: React.FC<{ albumId?: string }> = ({ albumId }) => {
311333
</IconButton>
312334
</Tooltip>
313335
{albumId && (
314-
<Tooltip title="Remove from album">
315-
<span>
316-
<IconButton
317-
color="inherit"
318-
onClick={handleRemoveFromAlbum}
319-
disabled={removeFromAlbumMutation.isPending}
320-
aria-label="Remove from album"
336+
<>
337+
<Tooltip title="Remove from album">
338+
<span>
339+
<IconButton
340+
color="inherit"
341+
onClick={() => setOpenRemoveFromAlbumDialog(true)}
342+
disabled={removeFromAlbumMutation.isPending}
343+
aria-label="Remove from album"
344+
>
345+
<RemoveCircleOutlineIcon />
346+
</IconButton>
347+
</span>
348+
</Tooltip>
349+
<Dialog
350+
open={openRemoveFromAlbumDialog}
351+
onClose={() => setOpenRemoveFromAlbumDialog(false)}
352+
aria-labelledby="remove-album-dialog-title"
353+
aria-describedby="remove-album-dialog-description"
354+
>
355+
<DialogTitle
356+
id="remove-album-dialog-title"
357+
sx={{ display: 'flex', alignItems: 'center', gap: 1 }}
358+
>
359+
<RemoveCircleOutlineIcon color="error" sx={{ fontSize: 32 }} />
360+
Remove from album {selectedImages.length}{' '}
361+
{selectedImages.length === 1 ? 'item' : 'items'}?
362+
</DialogTitle>
363+
<Typography
364+
id="remove-album-dialog-description"
365+
sx={{ px: 3, pb: 1, color: 'text.secondary' }}
321366
>
322-
<RemoveCircleOutlineIcon />
323-
</IconButton>
324-
</span>
325-
</Tooltip>
367+
This action will remove the selected{' '}
368+
{selectedImages.length === 1 ? 'item' : 'items'} from album.
369+
</Typography>
370+
<DialogActions>
371+
<Button
372+
onClick={() => setOpenRemoveFromAlbumDialog(false)}
373+
variant="outlined"
374+
>
375+
Cancel
376+
</Button>
377+
<Button
378+
onClick={() => {
379+
handleRemoveFromAlbum();
380+
setOpenRemoveFromAlbumDialog(false);
381+
}}
382+
color="error"
383+
variant="contained"
384+
>
385+
Remove from Album
386+
</Button>
387+
</DialogActions>
388+
</Dialog>
389+
</>
326390
)}
327391
<Tooltip title="Delete">
328392
<IconButton
@@ -392,9 +456,7 @@ export const ImageGallery: React.FC<{ albumId?: string }> = ({ albumId }) => {
392456
</Typography>
393457

394458
{selectedImages.length > 0 && !albumId && (
395-
<Tooltip
396-
title="Add to Album"
397-
>
459+
<Tooltip title="Add to Album">
398460
<span>
399461
<Button
400462
variant="outlined"

0 commit comments

Comments
 (0)