-
Notifications
You must be signed in to change notification settings - Fork 1
fix: 토글에 따른 사진 선택 로직 개선 #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,6 +170,7 @@ export default function PhotoList({ | |
| const isAllSelected = | ||
| selectablePhotos.length > 0 && | ||
| selectablePhotos.every(({ photoId }) => selectedPhotoIds.has(photoId)); | ||
| const hasAnySelected = selectedPhotos.length > 0; | ||
|
|
||
| const selectableStorePhotos = useMemo( | ||
| () => | ||
|
|
@@ -181,7 +182,7 @@ export default function PhotoList({ | |
| ); | ||
|
|
||
| const handleToggleSelectAll = () => { | ||
| if (isAllSelected) { | ||
| if (hasAnySelected) { | ||
| setIsSelectAllMode(false); | ||
| clearSelectedPhotos(); | ||
| return; | ||
|
|
@@ -206,6 +207,20 @@ export default function PhotoList({ | |
| } | ||
| }, [isSelectAllMode, mode, selectableStorePhotos, setSelectedPhotos]); | ||
|
|
||
| // includeMyPhotos 토글 변경 시, 필터에서 사라진 사진을 selectedPhotos에서 제거 | ||
| 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)); | ||
|
|
||
| if (filtered.length !== currentSelected.length) { | ||
| setSelectedPhotos(filtered); | ||
| setIsSelectAllMode(false); | ||
| } | ||
| }, [mode, selectablePhotos, setSelectedPhotos]); | ||
|
Comment on lines
+211
to
+222
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
이 계산은 const selectableIds = useMemo(
() => new Set(selectablePhotos.map((p) => p.photoId)),
[selectablePhotos],
);
useEffect(() => {
if (mode !== 'select') return;
const currentSelected = useSelectedPhotosStore.getState().selectedPhotos;
const filtered = currentSelected.filter((p) => selectableIds.has(p.id));
if (filtered.length !== currentSelected.length) {
setSelectedPhotos(filtered);
setIsSelectAllMode(false);
}
}, [mode, selectableIds, setSelectedPhotos]);위와 같이 수정하면 |
||
|
|
||
| return ( | ||
| <section ref={photoListRef} className='relative p-4'> | ||
| <div ref={anchorRef} className='invisible absolute top-[-72px] left-0' /> | ||
|
|
@@ -241,7 +256,7 @@ export default function PhotoList({ | |
| }} | ||
| onClick={handleToggleSelectAll} | ||
| > | ||
| {isAllSelected ? '전체 선택 취소' : '전체 선택'} | ||
| {hasAnySelected ? '전체 선택 취소' : '전체 선택'} | ||
| </button> | ||
| <button | ||
| type='button' | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isAllSelected에서hasAnySelected로 조건을 변경하면서, 일부 사진만 선택된 상태에서 전체를 선택하는 기능이 사라졌습니다. 현재 로직에서는 일부라도 선택되어 있으면 "전체 선택 취소"만 가능하여, 사용자가 전체 선택을 하려면 먼저 모든 선택을 해제해야 합니다. 이는 사용자 경험을 저해할 수 있습니다.예를 들어, 100장 중 99장을 선택한 사용자가 나머지 한 장을 선택하기 위해 "전체 선택"을 누르고 싶을 수 있지만, 현재는 불가능합니다.
세 가지 상태(선택 없음, 일부 선택, 전체 선택)를 구분하여 처리하는 것을 고려해보세요. 예를 들어, 일부만 선택된 상태에서는 여전히 "전체 선택" 버튼을 표시하여 사용자가 나머지 항목을 쉽게 선택할 수 있도록 할 수 있습니다.