diff --git a/src/feature/album/detail/components/PhotoList.tsx b/src/feature/album/detail/components/PhotoList.tsx index 8dff315..f1803a8 100644 --- a/src/feature/album/detail/components/PhotoList.tsx +++ b/src/feature/album/detail/components/PhotoList.tsx @@ -181,16 +181,21 @@ export default function PhotoList({ [selectablePhotos], ); - const handleToggleSelectAll = () => { - if (hasAnySelected) { - setIsSelectAllMode(false); - clearSelectedPhotos(); - return; - } + const selectablePhotoIds = useMemo( + () => new Set(selectablePhotos.map(({ photoId }) => photoId)), + [selectablePhotos], + ); + + const handleSelectAll = () => { setIsSelectAllMode(true); setSelectedPhotos(selectableStorePhotos); }; + const handleClearAll = () => { + setIsSelectAllMode(false); + clearSelectedPhotos(); + }; + useEffect(() => { if (mode !== 'select') return; if (!isSelectAllMode) return; @@ -211,15 +216,16 @@ export default function PhotoList({ useEffect(() => { if (mode !== 'select') return; - const selectableIds = new Set(selectablePhotos.map((p) => p.photoId)); const currentSelected = useSelectedPhotosStore.getState().selectedPhotos; - const filtered = currentSelected.filter((p) => selectableIds.has(p.id)); + const filtered = currentSelected.filter((p) => + selectablePhotoIds.has(p.id), + ); if (filtered.length !== currentSelected.length) { setSelectedPhotos(filtered); setIsSelectAllMode(false); } - }, [mode, selectablePhotos, setSelectedPhotos]); + }, [mode, selectablePhotoIds, setSelectedPhotos]); return (
@@ -248,16 +254,30 @@ export default function PhotoList({ ) : (
- +
+ + {hasAnySelected && ( + + )} +