Skip to content

Commit

Permalink
Merge pull request #322 from psteinroe/fix/has-more
Browse files Browse the repository at this point in the history
fix: set hasMore to false if list is currently empty
  • Loading branch information
psteinroe authored Nov 8, 2023
2 parents cff7840 + e225881 commit eb1ad24
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-keys-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@supabase-cache-helpers/postgrest-core": patch
---

fix: set hasMore to false if result is currently empty
16 changes: 16 additions & 0 deletions packages/postgrest-core/__tests__/mutate/transformers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { toHasMorePaginationCacheData } from '../../src/mutate/transformers';

describe('toHasMorePaginationCacheData', () => {
it('should set hasMore to false if there are no items in the cache currently', async () => {
expect(toHasMorePaginationCacheData([{ test: 'a' }], [], 21)).toEqual([
{
data: [
{
test: 'a',
},
],
hasMore: false,
},
]);
});
});
2 changes: 1 addition & 1 deletion packages/postgrest-core/__tests__/upsert-item.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ describe('upsertItem', () => {
]);
});

it('should set hasMore properky', async () => {
it('should set hasMore properly', async () => {
expect(
await mutateFnResult(
{ id_1: '0', id_2: '0', value: 'test' },
Expand Down
4 changes: 3 additions & 1 deletion packages/postgrest-core/src/mutate/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const toHasMorePaginationCacheData = <
resultArray[chunkIndex] = {
data: [],
hasMore:
hasMoreCache[chunkIndex] ?? hasMoreCache[hasMoreCache.length - 1],
hasMoreCache[chunkIndex] ??
hasMoreCache[hasMoreCache.length - 1] ??
false,
}; // start a new chunk
}

Expand Down

2 comments on commit eb1ad24

@vercel
Copy link

@vercel vercel bot commented on eb1ad24 Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

supabase-cache-helpers-react-query – ./examples/react-query

supabase-cache-helpers-react-query-psteinroe.vercel.app
supabase-cache-helpers-react-query.vercel.app
supabase-cache-helpers-react-query-git-main-psteinroe.vercel.app

@vercel
Copy link

@vercel vercel bot commented on eb1ad24 Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

supabase-cache-helpers-swr-demo – ./examples/swr

supabase-cache-helpers-swr.vercel.app
supabase-cache-helpers-swr-demo-git-main-psteinroe.vercel.app
supabase-cache-helpers-swr-demo-psteinroe.vercel.app

Please sign in to comment.