diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-03-09 00:38:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-09 00:38:02 +0100 |
| commit | 5b6639a3cf9b6c63045cb82e6ef1a43b0742c367 (patch) | |
| tree | 4e7cebf9f6b094d405e96febe743fea514cfca9f /src/services/graphql/queries.ts | |
| parent | b0d9d8cb1c8c4a4d2b9234bbfdc7195fb563b21a (diff) | |
feat: provide pagination for users with js disabled (#13)
* chore: add a Pagination component
* chore: add blog pages
* chore: fallback to page number based navigation if JS disabled
* chore: update translation
Diffstat (limited to 'src/services/graphql/queries.ts')
| -rw-r--r-- | src/services/graphql/queries.ts | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/services/graphql/queries.ts b/src/services/graphql/queries.ts index e56590f..8dd8563 100644 --- a/src/services/graphql/queries.ts +++ b/src/services/graphql/queries.ts @@ -1,6 +1,11 @@ import { Slug } from '@ts/types/app'; import { Article, PostBy, TotalArticles } from '@ts/types/articles'; -import { AllPostsSlug, PostsList, RawPostsList } from '@ts/types/blog'; +import { + AllPostsSlug, + LastPostCursor, + PostsList, + RawPostsList, +} from '@ts/types/blog'; import { Comment, CommentsByPostId } from '@ts/types/comments'; import { AllTopics, @@ -510,3 +515,25 @@ export const getAllThematics = async (): Promise<ThematicPreview[]> => { const response = await fetchApi<AllThematics>(query, null); return response.thematics.nodes; }; + +export const getEndCursor = async ({ + first = 10, +}: { + first: number; +}): Promise<string> => { + const query = gql` + query EndCursorAfter($first: Int) { + posts(first: $first) { + pageInfo { + hasNextPage + endCursor + } + } + } + `; + + const variables = { first }; + const response = await fetchApi<LastPostCursor>(query, variables); + + return response.posts.pageInfo.endCursor; +}; |
