-
,
- iconSelected:
,
- }, {
- value: 'hidden',
- icon:
,
- }, {
- value: 'search',
- icon: isLoading
- ?
- :
,
- }]}
- selected={mode}
- onChange={setMode}
+
setQuery(e.target.value)}
/>
- {showQuery &&
-
setQuery(e.target.value)}
- />}
-
- {(showQuery && query ? photosQuery : photos).map(photo => (
-
- {renderPhoto({
- photo,
- onClick: () => onChange(photo.id),
- })}
-
- ))}
+
+
+
+ {(showQuery && query ? photosQuery : photos)
+ .map(photo => renderPhotoButton(photo))}
+ {!(showQuery && query) && photosCount > photos.length &&
+
+ {({ key, photos }) => (
+
+ {photos.map(photo => renderPhotoButton(photo))}
+
+ )}
+ }
diff --git a/src/photo/usePhotoQuery.ts b/src/photo/usePhotoQuery.ts
index eadfba60..eeb425bd 100644
--- a/src/photo/usePhotoQuery.ts
+++ b/src/photo/usePhotoQuery.ts
@@ -2,16 +2,22 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { Photo } from '.';
import { useDebounce } from 'use-debounce';
-import { searchPhotosAction } from './actions';
+import { getPhotosAction, searchPhotosPublicAction } from './actions';
const formatQuery = (query: string) =>
query.trim().toLocaleLowerCase();
-export default function usePhotoQuery(
- query: string,
+export default function usePhotoQuery({
+ query,
isEnabled = true,
minimumQueryLength = 2,
-) {
+ isPrivate,
+}: {
+ query: string
+ isEnabled?: boolean
+ minimumQueryLength?: number
+ isPrivate?: boolean
+}) {
const [isLoading, setIsLoading] = useState(false);
const queryFormatted = useMemo(() =>
@@ -30,7 +36,9 @@ export default function usePhotoQuery(
useEffect(() => {
if (queryDebounced.length >= minimumQueryLength && isEnabled) {
setIsLoading(true);
- searchPhotosAction(queryDebounced)
+ (isPrivate
+ ? getPhotosAction({ query: queryDebounced })
+ : searchPhotosPublicAction(queryDebounced))
.then(setPhotos)
.finally(() => setIsLoading(false));
}
@@ -38,6 +46,7 @@ export default function usePhotoQuery(
queryDebounced,
minimumQueryLength,
isEnabled,
+ isPrivate,
]);
useEffect(() => {