UNPKG

threed-garden

Version:

ThreeD Garden: WebGL 3D Environment Interface for Next.JS React TypeScript Three.JS React-Three Physics, 2D Paper.JS; APIs: Apollo GraphQL, WordPress; CSS: Tailwind, Radix-UI; Libraries: FarmBot 3D; AI: OpenAI, DeepSeek

70 lines (63 loc) 1.8 kB
import { cache } from 'react'; export type PageProps = { params?: any; children?: React.ReactNode; }; export type Category = { name: string; slug: string; count: number; items: Omit<Category, 'items'>[]; }; export const getCategories = cache((): Category[] => [ { name: 'Electronics', slug: 'electronics', count: 11, items: [ { name: 'Phones', slug: 'phones', count: 4 }, { name: 'Tablets', slug: 'tablets', count: 5 }, { name: 'Laptops', slug: 'laptops', count: 2 }, ], }, { name: 'Clothing', slug: 'clothing', count: 12, items: [ { name: 'Tops', slug: 'tops', count: 3 }, { name: 'Shorts', slug: 'shorts', count: 4 }, { name: 'Shoes', slug: 'shoes', count: 5 }, ], }, { name: 'Books', slug: 'books', count: 10, items: [ { name: 'Fiction', slug: 'fiction', count: 5 }, { name: 'Biography', slug: 'biography', count: 2 }, { name: 'Education', slug: 'education', count: 3 }, ], }, ]); export async function fetchCategoryBySlug(slug: string | undefined) { // Assuming it always return expected categories return getCategories().find((category) => category.slug === slug); } export async function fetchCategories(): Promise<Category[]> { return getCategories(); } async function findSubCategory( category: Category | undefined, subCategorySlug: string | undefined, ) { return category?.items.find((category) => category.slug === subCategorySlug); } export async function fetchSubCategory( categorySlug: string | undefined, subCategorySlug: string | undefined, ) { const category = await fetchCategoryBySlug(categorySlug); return findSubCategory(category, subCategorySlug); }