Skip to content

Commit

Permalink
fix(pagination-repolist): prev-next pages access and fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
azinit committed Nov 25, 2020
1 parent de6ff71 commit ab1e2aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/features/repo-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ const RepoList = ({ username }: Props) => {
ownerAffiliations: [tabEnum],
after,
before,
/**
* @variant (!before, !after) => Первый вход, фетчим первые {PAGE_SIZE}
* @variant (after, !before) => След. страница, фетчим след. первые {PAGE_SIZE}
* @variant (!after, before) => Пред. страница, фетчим пред. последние {PAGE_SIZE}
* @variant (after, before) => (невозможна из-за реализации)
*/
first: (!before && PAGE_SIZE) || undefined,
last: (before && PAGE_SIZE) || undefined,
},
});
const { pageInfo, totalCount = 0, nodes } = data?.user?.repositories || {};
Expand Down
8 changes: 6 additions & 2 deletions src/features/repo-list/queries.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ export type ReposQueryVariables = Types.Exact<{
ownerAffiliations?: Types.Maybe<ReadonlyArray<Types.Maybe<Types.RepositoryAffiliation>>>;
after?: Types.Maybe<Types.Scalars['String']>;
before?: Types.Maybe<Types.Scalars['String']>;
first?: Types.Maybe<Types.Scalars['Int']>;
last?: Types.Maybe<Types.Scalars['Int']>;
}>;


export type ReposQuery = { readonly user?: Types.Maybe<{ readonly id: string, readonly repositories: { readonly totalCount: number, readonly pageInfo: { readonly endCursor?: Types.Maybe<string>, readonly startCursor?: Types.Maybe<string>, readonly hasNextPage: boolean, readonly hasPreviousPage: boolean }, readonly nodes?: Types.Maybe<ReadonlyArray<Types.Maybe<{ readonly id: string, readonly name: string, readonly updatedAt: any, readonly viewerHasStarred: boolean, readonly url: any, readonly primaryLanguage?: Types.Maybe<{ readonly color?: Types.Maybe<string>, readonly name: string }> }>>> } }> };


export const ReposDocument = gql`
query Repos($login: String!, $ownerAffiliations: [RepositoryAffiliation], $after: String, $before: String) {
query Repos($login: String!, $ownerAffiliations: [RepositoryAffiliation], $after: String, $before: String, $first: Int, $last: Int) {
user(login: $login) {
id
repositories(ownerAffiliations: $ownerAffiliations, first: 30, orderBy: {field: PUSHED_AT, direction: DESC}, after: $after, before: $before) {
repositories(ownerAffiliations: $ownerAffiliations, orderBy: {field: PUSHED_AT, direction: DESC}, after: $after, before: $before, first: $first, last: $last) {
pageInfo {
endCursor
startCursor
Expand Down Expand Up @@ -58,6 +60,8 @@ export const ReposDocument = gql`
* ownerAffiliations: // value for 'ownerAffiliations'
* after: // value for 'after'
* before: // value for 'before'
* first: // value for 'first'
* last: // value for 'last'
* },
* });
*/
Expand Down
4 changes: 2 additions & 2 deletions src/features/repo-list/queries.gql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
query Repos ($login: String!, $ownerAffiliations: [RepositoryAffiliation], $after: String, $before: String) {
query Repos ($login: String!, $ownerAffiliations: [RepositoryAffiliation], $after: String, $before: String, $first: Int, $last: Int) {
user(login: $login) {
id
repositories(ownerAffiliations: $ownerAffiliations, first: 30, orderBy: {field: PUSHED_AT, direction: DESC}, after: $after, before: $before) {
repositories(ownerAffiliations: $ownerAffiliations, orderBy: {field: PUSHED_AT, direction: DESC}, after: $after, before: $before, first: $first, last: $last) {
pageInfo {
endCursor
startCursor
Expand Down

0 comments on commit ab1e2aa

Please sign in to comment.