From 5b6639a3cf9b6c63045cb82e6ef1a43b0742c367 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Wed, 9 Mar 2022 00:38:02 +0100 Subject: 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 --- src/services/graphql/queries.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/services/graphql/queries.ts') 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 => { const response = await fetchApi(query, null); return response.thematics.nodes; }; + +export const getEndCursor = async ({ + first = 10, +}: { + first: number; +}): Promise => { + const query = gql` + query EndCursorAfter($first: Int) { + posts(first: $first) { + pageInfo { + hasNextPage + endCursor + } + } + } + `; + + const variables = { first }; + const response = await fetchApi(query, variables); + + return response.posts.pageInfo.endCursor; +}; -- cgit v1.2.3