Fixes search page bugs. (#1019)

This commit is contained in:
Michael Novotny
2023-05-12 16:02:51 -07:00
committed by GitHub
parent a0c0d10fae
commit f5dade74fb
8 changed files with 54 additions and 13 deletions

View File

@@ -257,16 +257,26 @@ export async function getCollection(handle: string): Promise<Collection | undefi
return reshapeCollection(res.body.data.collection);
}
export async function getCollectionProducts(handle: string): Promise<Product[]> {
export async function getCollectionProducts({
collection,
reverse,
sortKey
}: {
collection: string;
reverse?: boolean;
sortKey?: string;
}): Promise<Product[]> {
const res = await shopifyFetch<ShopifyCollectionProductsOperation>({
query: getCollectionProductsQuery,
variables: {
handle
handle: collection,
reverse,
sortKey
}
});
if (!res.body.data.collection) {
console.log('No collection found for handle', handle);
console.log(`No collection found for \`${collection}\``);
return [];
}

View File

@@ -37,9 +37,13 @@ export const getCollectionsQuery = /* GraphQL */ `
`;
export const getCollectionProductsQuery = /* GraphQL */ `
query getCollectionProducts($handle: String!) {
query getCollectionProducts(
$handle: String!
$sortKey: ProductCollectionSortKeys
$reverse: Boolean
) {
collection(handle: $handle) {
products(first: 100) {
products(sortKey: $sortKey, reverse: $reverse, first: 100) {
edges {
node {
...product

View File

@@ -201,6 +201,8 @@ export type ShopifyCollectionProductsOperation = {
};
variables: {
handle: string;
reverse?: boolean;
sortKey?: string;
};
};