PluginProbe
Extendify / trunk
Extendify vtrunk
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
← All changes | src/Draft/hooks/useUnsplashImages.js +11 -3 3.1.1 → trunk View file →
@@ -1,4 +1,8 @@
1 +import {
2 + DEFAULT_IMAGE_SEARCH,
3 + resolveImageSearch,
4 +} from '@shared/lib/image-search-defaults';
1 5 import { fetchImages } from '@shared/lib/unsplash';
2 6 import { useUnsplashCacheStore } from '@shared/state/unsplash-cache';
3 7 import useSWRImmutable from 'swr/immutable';
4 8
@@ -3,15 +7,19 @@
3 7 import useSWRImmutable from 'swr/immutable';
4 8
5 9 const searchImages = async (search, source = null) => {
6 10 const cache = useUnsplashCacheStore.getState();
7 - if (search === 'unsplash' && !cache.isEmpty() && !cache.hasExpired()) {
11 + if (
12 + search === DEFAULT_IMAGE_SEARCH &&
13 + !cache.isEmpty() &&
14 + !cache.hasExpired()
15 + ) {
8 16 return cache.images;
9 17 }
10 - return await fetchImages(search, source);
18 + return await fetchImages(resolveImageSearch(search), source);
11 19 };
12 20
13 21 export const useUnsplashImages = (search, source = null) => {
14 - const key = search || 'unsplash';
22 + const key = search || DEFAULT_IMAGE_SEARCH;
15 23 const { data, error } = useSWRImmutable(key, () => searchImages(key, source));
16 24 return { data, error, loading: !data && !error };
17 25 };