Skip to content

Commit

Permalink
fix(map): Fix latest collection refresh [IOPLAT-4170]
Browse files Browse the repository at this point in the history
  • Loading branch information
ancashoria authored Jan 27, 2021
1 parent 00a5376 commit c3ba3f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ import { CollectionsCard } from './CollectionsCard';
export default function WithData(props) {
const { group } = props;

const { data } = useLocations({
select: 'slug,name,id,organization,type,updatedAt',
filter: ['type', '==', LocationTypeEnum.COLLECTION].join(''),
page: { size: 5 },
sort: '-updatedAt',
group: group.toString(),
});
const { data } = useLocations(
{
select: 'slug,name,id,organization,type,updatedAt',
filter: ['type', '==', LocationTypeEnum.COLLECTION].join(''),
page: { size: 5 },
sort: '-updatedAt',
group: group.toString(),
},
{
revalidateAll: true,
}
);

return <CollectionsCard data={data} {...props} />;
}
13 changes: 10 additions & 3 deletions packages/earth-map/src/fetchers/useLocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { groupBy, sortBy } from 'lodash';
import { noop } from 'lodash/fp';
import { useSWRInfinite } from 'swr';
import { useSWRInfinite, SWRInfiniteConfigInterface } from 'swr';

import { BaseAPIService, metaDeserializer } from '../services/base/APIBase';
import { encodeQueryToURL } from '../utils/query';
Expand All @@ -38,7 +38,10 @@ interface IQueryLocation {

const DEFAULT_PAGE_SIZE = 30;

export default function useLocations(query: IQueryLocation) {
export default function useLocations(
query: IQueryLocation,
passedOptions: SWRInfiniteConfigInterface = {}
) {
const swrKeyLoader = (pageIndex: number, previousPage: any): string => {
if (previousPage && !previousPage.data) {
return null; // reached the end;
Expand Down Expand Up @@ -88,7 +91,11 @@ export default function useLocations(query: IQueryLocation) {
});
};

const { data: rawData, isValidating, size, setSize }: any = useSWRInfinite(swrKeyLoader, fetcher);
const { data: rawData, isValidating, size, setSize }: any = useSWRInfinite(
swrKeyLoader,
fetcher,
passedOptions
);

if (!rawData) {
return {};
Expand Down

0 comments on commit c3ba3f0

Please sign in to comment.