Clear batch edit state when selection stops
This commit is contained in:
parent
2feb4cf088
commit
0240bd56d6
@ -4,7 +4,7 @@ import LoaderButton from '@/components/primitives/LoaderButton';
|
|||||||
import AppGrid from '@/components/AppGrid';
|
import AppGrid from '@/components/AppGrid';
|
||||||
import { clsx } from 'clsx/lite';
|
import { clsx } from 'clsx/lite';
|
||||||
import { IoCloseSharp } from 'react-icons/io5';
|
import { IoCloseSharp } from 'react-icons/io5';
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import { Tags } from '@/tag';
|
import { Tags } from '@/tag';
|
||||||
import FieldsetTag from '@/tag/FieldsetTag';
|
import FieldsetTag from '@/tag/FieldsetTag';
|
||||||
import { batchPhotoAction } from '@/photo/actions';
|
import { batchPhotoAction } from '@/photo/actions';
|
||||||
@ -44,15 +44,17 @@ export default function AdminBatchEditPanelClient({
|
|||||||
selectAllCount,
|
selectAllCount,
|
||||||
isPerformingSelectEdit,
|
isPerformingSelectEdit,
|
||||||
setIsPerformingSelectEdit,
|
setIsPerformingSelectEdit,
|
||||||
|
albumTitles,
|
||||||
|
setAlbumTitles,
|
||||||
|
tags,
|
||||||
|
setTags,
|
||||||
|
tagErrorMessage,
|
||||||
|
setTagErrorMessage,
|
||||||
} = useSelectPhotosState();
|
} = useSelectPhotosState();
|
||||||
|
|
||||||
const appText = useAppText();
|
const appText = useAppText();
|
||||||
|
|
||||||
const [albumTitles, setAlbumsTitles] = useState<string>();
|
|
||||||
const isInAlbumMode = albumTitles !== undefined;
|
const isInAlbumMode = albumTitles !== undefined;
|
||||||
|
|
||||||
const [tags, setTags] = useState<string>();
|
|
||||||
const [tagErrorMessage, setTagErrorMessage] = useState('');
|
|
||||||
const isInTagMode = tags !== undefined;
|
const isInTagMode = tags !== undefined;
|
||||||
|
|
||||||
const batchPhotoActionArguments = (
|
const batchPhotoActionArguments = (
|
||||||
@ -103,9 +105,9 @@ export default function AdminBatchEditPanelClient({
|
|||||||
className="translate-y-[0.5px]"
|
className="translate-y-[0.5px]"
|
||||||
/>}
|
/>}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setAlbumsTitles(undefined);
|
setAlbumTitles?.(undefined);
|
||||||
setTags(undefined);
|
setTags?.(undefined);
|
||||||
setTagErrorMessage('');
|
setTagErrorMessage?.('');
|
||||||
}}
|
}}
|
||||||
disabled={isPerformingSelectEdit}
|
disabled={isPerformingSelectEdit}
|
||||||
/>
|
/>
|
||||||
@ -182,14 +184,14 @@ export default function AdminBatchEditPanelClient({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<LoaderButton
|
<LoaderButton
|
||||||
onClick={() => setAlbumsTitles('')}
|
onClick={() => setAlbumTitles?.('')}
|
||||||
disabled={isFormDisabled}
|
disabled={isFormDisabled}
|
||||||
icon={<IconAlbum size={15} className="translate-y-[1.5px]" />}
|
icon={<IconAlbum size={15} className="translate-y-[1.5px]" />}
|
||||||
>
|
>
|
||||||
Album
|
Album
|
||||||
</LoaderButton>
|
</LoaderButton>
|
||||||
<LoaderButton
|
<LoaderButton
|
||||||
onClick={() => setTags('')}
|
onClick={() => setTags?.('')}
|
||||||
disabled={isFormDisabled}
|
disabled={isFormDisabled}
|
||||||
icon={<IconTag size={15} className="translate-y-[1.5px]" />}
|
icon={<IconTag size={15} className="translate-y-[1.5px]" />}
|
||||||
>
|
>
|
||||||
@ -234,7 +236,7 @@ export default function AdminBatchEditPanelClient({
|
|||||||
? <FieldsetAlbum
|
? <FieldsetAlbum
|
||||||
albumOptions={uniqueAlbums}
|
albumOptions={uniqueAlbums}
|
||||||
value={albumTitles}
|
value={albumTitles}
|
||||||
onChange={setAlbumsTitles}
|
onChange={setAlbumTitles}
|
||||||
readOnly={isPerformingSelectEdit}
|
readOnly={isPerformingSelectEdit}
|
||||||
openOnLoad
|
openOnLoad
|
||||||
hideLabel
|
hideLabel
|
||||||
@ -244,7 +246,7 @@ export default function AdminBatchEditPanelClient({
|
|||||||
tags={tags}
|
tags={tags}
|
||||||
tagOptions={uniqueTags}
|
tagOptions={uniqueTags}
|
||||||
placeholder={`Tag ${photosText} ...`}
|
placeholder={`Tag ${photosText} ...`}
|
||||||
onChange={setTags}
|
onChange={tags => setTags?.(tags)}
|
||||||
onError={setTagErrorMessage}
|
onError={setTagErrorMessage}
|
||||||
readOnly={isPerformingSelectEdit}
|
readOnly={isPerformingSelectEdit}
|
||||||
openOnLoad
|
openOnLoad
|
||||||
|
|||||||
@ -51,6 +51,10 @@ export default function SelectPhotosProvider({
|
|||||||
const [isPerformingSelectEdit, setIsPerformingSelectEdit] =
|
const [isPerformingSelectEdit, setIsPerformingSelectEdit] =
|
||||||
useState(false);
|
useState(false);
|
||||||
|
|
||||||
|
const [albumTitles, setAlbumTitles] = useState<string>();
|
||||||
|
const [tags, setTags] = useState<string>();
|
||||||
|
const [tagErrorMessage, setTagErrorMessage] = useState('');
|
||||||
|
|
||||||
const getPhotoGridElements = useCallback(() =>
|
const getPhotoGridElements = useCallback(() =>
|
||||||
document.querySelectorAll(`[${DATA_KEY_PHOTO_GRID}=true]`)
|
document.querySelectorAll(`[${DATA_KEY_PHOTO_GRID}=true]`)
|
||||||
, []);
|
, []);
|
||||||
@ -118,6 +122,9 @@ export default function SelectPhotosProvider({
|
|||||||
setIsSelectingAllPhotos(false);
|
setIsSelectingAllPhotos(false);
|
||||||
setSelectAllPhotoOptions(undefined);
|
setSelectAllPhotoOptions(undefined);
|
||||||
setSelectAllCount(undefined);
|
setSelectAllCount(undefined);
|
||||||
|
setAlbumTitles(undefined);
|
||||||
|
setTags(undefined);
|
||||||
|
setTagErrorMessage('');
|
||||||
}
|
}
|
||||||
}, [isSelectingPhotos, getPhotoGridElements]);
|
}, [isSelectingPhotos, getPhotoGridElements]);
|
||||||
|
|
||||||
@ -136,6 +143,12 @@ export default function SelectPhotosProvider({
|
|||||||
togglePhotoSelection,
|
togglePhotoSelection,
|
||||||
isPerformingSelectEdit,
|
isPerformingSelectEdit,
|
||||||
setIsPerformingSelectEdit,
|
setIsPerformingSelectEdit,
|
||||||
|
albumTitles,
|
||||||
|
setAlbumTitles,
|
||||||
|
tags,
|
||||||
|
setTags,
|
||||||
|
tagErrorMessage,
|
||||||
|
setTagErrorMessage,
|
||||||
}}>
|
}}>
|
||||||
{children}
|
{children}
|
||||||
</SelectPhotosContext.Provider>
|
</SelectPhotosContext.Provider>
|
||||||
|
|||||||
@ -5,16 +5,22 @@ export type SelectPhotosState = {
|
|||||||
canCurrentPageSelectPhotos?: boolean
|
canCurrentPageSelectPhotos?: boolean
|
||||||
isSelectingPhotos?: boolean
|
isSelectingPhotos?: boolean
|
||||||
isSelectingAllPhotos?: boolean
|
isSelectingAllPhotos?: boolean
|
||||||
shouldShowSelectAll?: boolean
|
|
||||||
toggleIsSelectingAllPhotos?: () => void
|
|
||||||
startSelectingPhotos?: () => void
|
startSelectingPhotos?: () => void
|
||||||
stopSelectingPhotos?: () => void
|
stopSelectingPhotos?: () => void
|
||||||
|
shouldShowSelectAll?: boolean
|
||||||
|
toggleIsSelectingAllPhotos?: () => void
|
||||||
selectedPhotoIds?: string[]
|
selectedPhotoIds?: string[]
|
||||||
selectAllPhotoOptions?: PhotoQueryOptions
|
selectAllPhotoOptions?: PhotoQueryOptions
|
||||||
selectAllCount?: number
|
selectAllCount?: number
|
||||||
togglePhotoSelection?: (photoId: string) => void
|
togglePhotoSelection?: (photoId: string) => void
|
||||||
isPerformingSelectEdit?: boolean
|
isPerformingSelectEdit?: boolean
|
||||||
setIsPerformingSelectEdit?: Dispatch<SetStateAction<boolean>>
|
setIsPerformingSelectEdit?: Dispatch<SetStateAction<boolean>>
|
||||||
|
albumTitles?: string
|
||||||
|
setAlbumTitles?: Dispatch<SetStateAction<string | undefined>>
|
||||||
|
tags?: string
|
||||||
|
setTags?: Dispatch<SetStateAction<string | undefined>>
|
||||||
|
tagErrorMessage?: string
|
||||||
|
setTagErrorMessage?: Dispatch<SetStateAction<string>>
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SelectPhotosContext = createContext<SelectPhotosState>({});
|
export const SelectPhotosContext = createContext<SelectPhotosState>({});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user