Skip to content

Commit

Permalink
chore(clerk-js,shared): Replace setCache with setData
Browse files Browse the repository at this point in the history
  • Loading branch information
panteliselef committed Oct 30, 2023
1 parent 32f4c06 commit 646f3de
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const InvitationPreview = withCardStateProvider((props: UserOrganizationI
})
.then(([updatedItem, organization]) => {
// Update cache in case another listener depends on it
void userInvitations?.setCache?.(cachedPages => populateCacheUpdateItem(updatedItem, cachedPages));
void userInvitations?.setData?.(cachedPages => populateCacheUpdateItem(updatedItem, cachedPages));
setAcceptedOrganization(organization);
})
.catch(err => handleError(err, [], card.setError));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const AcceptRejectInvitationButtons = (props: OrganizationSuggestionResou
const handleAccept = () => {
return card
.runAsync(props.accept)
.then(updatedItem => userSuggestions?.setCache?.(pages => populateCacheUpdateItem(updatedItem, pages)))
.then(updatedItem => userSuggestions?.setData?.(pages => populateCacheUpdateItem(updatedItem, pages)))
.catch(err => handleError(err, [], card.setError));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const AcceptRejectSuggestionButtons = (props: OrganizationSuggestionResource) =>
const handleAccept = () => {
return card
.runAsync(props.accept)
.then(updatedItem => userSuggestions?.setCache?.(pages => populateCacheUpdateItem(updatedItem, pages)))
.then(updatedItem => userSuggestions?.setData?.(pages => populateCacheUpdateItem(updatedItem, pages)))
.catch(err => handleError(err, [], card.setError));
};

Expand Down Expand Up @@ -81,7 +81,7 @@ const AcceptRejectInvitationButtons = (props: UserOrganizationInvitationResource
const handleAccept = () => {
return card
.runAsync(props.accept)
.then(updatedItem => userInvitations?.setCache?.(pages => populateCacheRemoveItem(updatedItem, pages)))
.then(updatedItem => userInvitations?.setData?.(pages => populateCacheRemoveItem(updatedItem, pages)))
.catch(err => handleError(err, [], card.setError));
};

Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/react/hooks/useOrganization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const undefinedPaginatedResource = {
hasNextPage: false,
hasPreviousPage: false,
revalidate: undefined,
setCache: undefined,
setData: undefined,
} as const;

export const useOrganization: UseOrganization = params => {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/react/hooks/useOrganizationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const undefinedPaginatedResource = {
hasNextPage: false,
hasPreviousPage: false,
revalidate: undefined,
setCache: undefined,
setData: undefined,
} as const;

type UseOrganizationList = <T extends UseOrganizationListParams>(
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/react/hooks/usePagesOrInfinite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export const usePagesOrInfinite: UsePagesOrInfinite = (params, fetcher, options,
const hasNextPage = count - offsetCount * pageSizeRef.current > page * pageSizeRef.current;
const hasPreviousPage = (page - 1) * pageSizeRef.current > offsetCount * pageSizeRef.current;

const setCache: CacheSetter = triggerInfinite
const setData: CacheSetter = triggerInfinite
? value =>
swrInfiniteMutate(value, {
revalidate: false,
Expand Down Expand Up @@ -234,6 +234,6 @@ export const usePagesOrInfinite: UsePagesOrInfinite = (params, fetcher, options,
// Let the hook return type define this type
revalidate: revalidate as any,
// Let the hook return type define this type
setCache: setCache as any,
setData: setData as any,
};
};
2 changes: 1 addition & 1 deletion packages/shared/src/react/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type PaginatedResources<T = unknown, Infinite = false, ArrayOrPaginated =
hasNextPage: boolean;
hasPreviousPage: boolean;
revalidate: () => Promise<void>;
setCache: Infinite extends true
setData: Infinite extends true
? // Array of pages of data
CacheSetter<(ArrayOrPaginated | undefined)[]>
: // Array of data
Expand Down

0 comments on commit 646f3de

Please sign in to comment.