Add ability to paginate through subcategories
This commit is contained in:
parent
f5aefb1c36
commit
d71324ced2
4 changed files with 28 additions and 13 deletions
|
@ -1,6 +1,6 @@
|
|||
import gql from "graphql-tag";
|
||||
|
||||
import { TypedQuery } from "../queries";
|
||||
import { pageInfoFragment, TypedQuery } from "../queries";
|
||||
import {
|
||||
CategoryDetails,
|
||||
CategoryDetailsVariables
|
||||
|
@ -38,6 +38,7 @@ export const categoryDetailsFragment = gql`
|
|||
|
||||
export const rootCategories = gql`
|
||||
${categoryFragment}
|
||||
${pageInfoFragment}
|
||||
query RootCategories(
|
||||
$first: Int
|
||||
$after: String
|
||||
|
@ -59,10 +60,7 @@ export const rootCategories = gql`
|
|||
}
|
||||
}
|
||||
pageInfo {
|
||||
endCursor
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
startCursor
|
||||
...PageInfoFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +72,7 @@ export const TypedRootCategoriesQuery = TypedQuery<RootCategories, {}>(
|
|||
export const categoryDetails = gql`
|
||||
${categoryFragment}
|
||||
${categoryDetailsFragment}
|
||||
${pageInfoFragment}
|
||||
query CategoryDetails(
|
||||
$id: ID!
|
||||
$first: Int
|
||||
|
@ -83,19 +82,19 @@ export const categoryDetails = gql`
|
|||
) {
|
||||
category(id: $id) {
|
||||
...CategoryDetailsFragment
|
||||
children(first: 20) {
|
||||
children(first: $first, after: $after, last: $last, before: $before) {
|
||||
edges {
|
||||
node {
|
||||
...CategoryFragment
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
...PageInfoFragment
|
||||
}
|
||||
}
|
||||
products(first: $first, after: $after, last: $last, before: $before) {
|
||||
pageInfo {
|
||||
endCursor
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
startCursor
|
||||
...PageInfoFragment
|
||||
}
|
||||
edges {
|
||||
cursor
|
||||
|
|
|
@ -40,9 +40,18 @@ export interface CategoryDetails_category_children_edges {
|
|||
node: CategoryDetails_category_children_edges_node;
|
||||
}
|
||||
|
||||
export interface CategoryDetails_category_children_pageInfo {
|
||||
__typename: "PageInfo";
|
||||
endCursor: string | null;
|
||||
hasNextPage: boolean;
|
||||
hasPreviousPage: boolean;
|
||||
startCursor: string | null;
|
||||
}
|
||||
|
||||
export interface CategoryDetails_category_children {
|
||||
__typename: "CategoryCountableConnection";
|
||||
edges: CategoryDetails_category_children_edges[];
|
||||
pageInfo: CategoryDetails_category_children_pageInfo;
|
||||
}
|
||||
|
||||
export interface CategoryDetails_category_products_pageInfo {
|
||||
|
|
|
@ -162,7 +162,9 @@ export const CategoryDetails: React.FC<CategoryDetailsProps> = ({
|
|||
};
|
||||
|
||||
const { loadNextPage, loadPreviousPage, pageInfo } = paginate(
|
||||
maybe(() => data.category.products.pageInfo),
|
||||
params.activeTab === CategoryPageTab.categories
|
||||
? maybe(() => data.category.children.pageInfo)
|
||||
: maybe(() => data.category.products.pageInfo),
|
||||
paginationState,
|
||||
params
|
||||
);
|
||||
|
|
|
@ -2,7 +2,12 @@
|
|||
/* eslint-disable */
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
import { SiteDomainInput, ShopSettingsInput, AddressInput, AuthorizationKeyType } from "./../../types/globalTypes";
|
||||
import {
|
||||
SiteDomainInput,
|
||||
ShopSettingsInput,
|
||||
AddressInput,
|
||||
AuthorizationKeyType
|
||||
} from "./../../types/globalTypes";
|
||||
|
||||
// ====================================================
|
||||
// GraphQL mutation operation: ShopSettingsUpdate
|
||||
|
@ -143,5 +148,5 @@ export interface ShopSettingsUpdate {
|
|||
export interface ShopSettingsUpdateVariables {
|
||||
shopDomainInput: SiteDomainInput;
|
||||
shopSettingsInput: ShopSettingsInput;
|
||||
addressInput: AddressInput;
|
||||
addressInput?: AddressInput | null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue