From 0a2e3d8e38c044d545044afc47495f75231863b2 Mon Sep 17 00:00:00 2001 From: Chloe Date: Fri, 5 Jul 2024 15:19:40 +0700 Subject: [PATCH] update inlinking blocks Signed-off-by: Chloe --- app/search/[collection]/page.tsx | 13 +++---------- components/engine-sizes/index.tsx | 20 +++++++------------- components/models/index.tsx | 20 +++++++------------- components/transmission-codes/index.tsx | 14 ++++---------- lib/shopify/index.ts | 14 ++------------ 5 files changed, 23 insertions(+), 58 deletions(-) diff --git a/app/search/[collection]/page.tsx b/app/search/[collection]/page.tsx index ab8346259..0ed8e2d56 100644 --- a/app/search/[collection]/page.tsx +++ b/app/search/[collection]/page.tsx @@ -22,7 +22,6 @@ import ProductsGridPlaceholder from 'components/layout/search/placeholder'; import SortingMenu from 'components/layout/search/sorting-menu'; import Models from 'components/models'; import TransmissionCode from 'components/transmission-codes'; -import { MAKE_FILTER_ID } from 'lib/constants'; import { Suspense } from 'react'; export async function generateMetadata({ @@ -125,26 +124,20 @@ export default async function CategorySearchPage(props: { {collectionHandle.startsWith('transmissions') && ( - + )} {['transmissions', 'engines', 'remanufactured-engines'].some((url) => collectionHandle.startsWith(url) ) && ( - + )} {['engines', 'remanufactured-engines'].some((url) => collectionHandle.startsWith(url)) && ( - + )} diff --git a/components/engine-sizes/index.tsx b/components/engine-sizes/index.tsx index 2a82fa465..1215265b2 100644 --- a/components/engine-sizes/index.tsx +++ b/components/engine-sizes/index.tsx @@ -1,23 +1,17 @@ -import { ENGINE_SIZE_FILTER_ID, MAKE_FILTER_ID } from 'lib/constants'; +import { ENGINE_SIZE_FILTER_ID } from 'lib/constants'; import { getProductFilters } from 'lib/shopify'; import { getCollectionUrl } from 'lib/utils'; import Link from 'next/link'; -const EngineSizes = async ({ - collectionHandle, - make -}: { - collectionHandle: string; - make?: string | string[]; -}) => { - // eg: collectionHandle = transmission-bmw-x5 - const makeFromCollectionHandle = collectionHandle.split('-')[1]; +const EngineSizes = async ({ collectionHandle }: { collectionHandle: string }) => { + // eg: collectionHandle = transmission_bmw_x5 + const makeFromCollectionHandle = collectionHandle.split('_')[1]; - if (!makeFromCollectionHandle && !make) { + if (!makeFromCollectionHandle) { return null; } const engineSizes = await getProductFilters( - { collection: collectionHandle, make }, + { collection: collectionHandle }, ENGINE_SIZE_FILTER_ID ); @@ -33,7 +27,7 @@ const EngineSizes = async ({
{engineSizes.values.map((engineSize) => (
diff --git a/components/models/index.tsx b/components/models/index.tsx index 2f91d1418..937e2b3f1 100644 --- a/components/models/index.tsx +++ b/components/models/index.tsx @@ -1,24 +1,18 @@ import { GlobeAltIcon } from '@heroicons/react/24/outline'; -import { MAKE_FILTER_ID, MODEL_FILTER_ID } from 'lib/constants'; +import { MODEL_FILTER_ID } from 'lib/constants'; import { getProductFilters } from 'lib/shopify'; import { getCollectionUrl } from 'lib/utils'; import Link from 'next/link'; -const Models = async ({ - collectionHandle, - make -}: { - collectionHandle: string; - make?: string | string[]; -}) => { - // eg: collectionHandle = transmission-bmw-x5 - const makeFromCollectionHandle = collectionHandle.split('-')[1]; +const Models = async ({ collectionHandle }: { collectionHandle: string }) => { + // eg: collectionHandle = transmission_bmw_x5 + const makeFromCollectionHandle = collectionHandle.split('_')[1]; - if (!makeFromCollectionHandle && !make) { + if (!makeFromCollectionHandle) { return null; } const transmissionModels = await getProductFilters( - { collection: collectionHandle, make }, + { collection: collectionHandle }, MODEL_FILTER_ID ); @@ -40,7 +34,7 @@ const Models = async ({
{transmissionModels.values.map((model) => (
{model.label}
diff --git a/components/transmission-codes/index.tsx b/components/transmission-codes/index.tsx index cd21f56fe..53218e20f 100644 --- a/components/transmission-codes/index.tsx +++ b/components/transmission-codes/index.tsx @@ -1,19 +1,13 @@ import { StarIcon } from '@heroicons/react/24/outline'; import Tag from 'components/tag'; -import { MAKE_FILTER_ID, TRANSMISSION_CODE_FILTER_ID } from 'lib/constants'; +import { TRANSMISSION_CODE_FILTER_ID } from 'lib/constants'; import { getProductFilters } from 'lib/shopify'; import { getCollectionUrl } from 'lib/utils'; import Link from 'next/link'; -const TransmissionCode = async ({ - collectionHandle, - make -}: { - collectionHandle: string; - make?: string | string[]; -}) => { +const TransmissionCode = async ({ collectionHandle }: { collectionHandle: string }) => { const transmissionCodes = await getProductFilters( - { collection: collectionHandle, make }, + { collection: collectionHandle }, TRANSMISSION_CODE_FILTER_ID ); @@ -34,7 +28,7 @@ const TransmissionCode = async ({
{transmissionCodes.values.map((transmissionCode) => (
diff --git a/lib/shopify/index.ts b/lib/shopify/index.ts index 65a0b9a58..df922c2a5 100644 --- a/lib/shopify/index.ts +++ b/lib/shopify/index.ts @@ -1181,24 +1181,14 @@ export const getFile = async (id: string) => { }; export async function getProductFilters( - { collection, make }: { collection: string; make?: string | string[] }, + { collection }: { collection: string }, filterId: string ): Promise { - const [namespace, metafieldKey] = MAKE_FILTER_ID.split('.').slice(-2); - const _make = Array.isArray(make) ? make : make ? [make] : undefined; - const res = await shopifyFetch({ query: getProductFiltersQuery, tags: [TAGS.collections, TAGS.products], variables: { - handle: collection, - ...(_make - ? { - filters: _make.map((make) => ({ - productMetafield: { namespace, key: metafieldKey, value: make } - })) - } - : {}) + handle: collection } });