Refactor photo chooser logic
This commit is contained in:
parent
017869fda9
commit
f244b8ce94
@ -18,6 +18,9 @@ import SegmentMenu from '@/components/SegmentMenu';
|
|||||||
import IconFavs from '@/components/icons/IconFavs';
|
import IconFavs from '@/components/icons/IconFavs';
|
||||||
import InfinitePhotoScroll from '../InfinitePhotoScroll';
|
import InfinitePhotoScroll from '../InfinitePhotoScroll';
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// Create empty state for all modes, including no search results
|
||||||
|
|
||||||
type Mode = 'all' | 'favs' | 'search';
|
type Mode = 'all' | 'favs' | 'search';
|
||||||
|
|
||||||
const CLASSNAME_GRID = 'grid grid-cols-3 gap-0.5';
|
const CLASSNAME_GRID = 'grid grid-cols-3 gap-0.5';
|
||||||
@ -98,6 +101,16 @@ export default function FieldsetPhotoChooser({
|
|||||||
{renderPhoto(photo)}
|
{renderPhoto(photo)}
|
||||||
</span>;
|
</span>;
|
||||||
|
|
||||||
|
const photosToShow = showQuery && query
|
||||||
|
? photosQuery
|
||||||
|
: mode === 'favs'
|
||||||
|
? photosFavs : photos;
|
||||||
|
|
||||||
|
const shouldPaginate =
|
||||||
|
!(showQuery && query) &&
|
||||||
|
photosCount > photos.length &&
|
||||||
|
mode !== 'favs';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FieldsetWithStatus {...{ label, value, onChange, type: 'hidden' }} />
|
<FieldsetWithStatus {...{ label, value, onChange, type: 'hidden' }} />
|
||||||
@ -176,16 +189,9 @@ export default function FieldsetPhotoChooser({
|
|||||||
'space-y-0.5',
|
'space-y-0.5',
|
||||||
)}>
|
)}>
|
||||||
<div className={CLASSNAME_GRID}>
|
<div className={CLASSNAME_GRID}>
|
||||||
{(showQuery && query
|
{photosToShow.map(photo => renderPhotoButton(photo))}
|
||||||
? photosQuery
|
|
||||||
: mode === 'favs'
|
|
||||||
? photosFavs : photos)
|
|
||||||
.map(photo => renderPhotoButton(photo))}
|
|
||||||
</div>
|
</div>
|
||||||
{
|
{shouldPaginate &&
|
||||||
!(showQuery && query) &&
|
|
||||||
photosCount > photos.length &&
|
|
||||||
mode !== 'favs' &&
|
|
||||||
<InfinitePhotoScroll
|
<InfinitePhotoScroll
|
||||||
cacheKey="photo-chooser"
|
cacheKey="photo-chooser"
|
||||||
initialOffset={photos.length}
|
initialOffset={photos.length}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user