feat: implement YMM filters

Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
Chloe
2024-05-15 20:53:22 +07:00
parent 57c5f42bf3
commit 7c60e4e7f4
12 changed files with 392 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
import clsx, { ClassValue } from 'clsx';
import { ReadonlyURLSearchParams } from 'next/navigation';
import { twMerge } from 'tailwind-merge';
import { Menu } from './shopify/types';
export const createUrl = (pathname: string, params: URLSearchParams | ReadonlyURLSearchParams) => {
const paramsString = params.toString();
@@ -55,3 +56,18 @@ export const parseMetaFieldValue = <T>(field: { value: string } | null): T | nul
return null;
}
};
export const findParentCollection = (menu: Menu[], collection: string): Menu | null => {
let parentCollection: Menu | null = null;
for (const item of menu) {
if (item.items.length) {
const hasParent = item.items.some((subItem) => subItem.path.includes(collection));
if (hasParent) {
return item;
} else {
parentCollection = findParentCollection(item.items, collection);
}
}
}
return parentCollection;
};