From 286627d50fcf77a79db2aecc54af440243aecddc Mon Sep 17 00:00:00 2001 From: Marcus Rein Date: Mon, 19 May 2025 11:01:09 -0400 Subject: [PATCH 1/4] Add initial setup for @graphprotocol/guides package with README, TypeScript configuration, and example code --- packages/guides/README.md | 22 ++++++++++++++++++++++ packages/guides/package.json | 17 +++++++++++++++++ packages/guides/src/index.ts | 1 + packages/guides/tsconfig.json | 11 +++++++++++ 4 files changed, 51 insertions(+) create mode 100644 packages/guides/README.md create mode 100644 packages/guides/package.json create mode 100644 packages/guides/src/index.ts create mode 100644 packages/guides/tsconfig.json diff --git a/packages/guides/README.md b/packages/guides/README.md new file mode 100644 index 000000000000..1876bf478aac --- /dev/null +++ b/packages/guides/README.md @@ -0,0 +1,22 @@ +# @graphprotocol/guides + +A collection of guides and utilities for The Graph documentation site. + +## Development + +``` +# Install dependencies (from project root) +pnpm install + +# In watch mode (inside this package) +pnpm --filter @graphprotocol/guides dev +``` + +## Build + +``` +# Build the TypeScript sources +pnpm --filter @graphprotocol/guides build +``` + +The compiled JavaScript files and type declarations will be output to `dist/`. \ No newline at end of file diff --git a/packages/guides/package.json b/packages/guides/package.json new file mode 100644 index 000000000000..17d732d05865 --- /dev/null +++ b/packages/guides/package.json @@ -0,0 +1,17 @@ +{ + "name": "@graphprotocol/guides", + "version": "0.1.0", + "private": true, + "main": "dist/index.js", + "types": "dist/index.d.ts", + "files": ["dist"], + "scripts": { + "build": "tsc -p tsconfig.json", + "dev": "tsc -w -p tsconfig.json", + "typecheck": "tsc --noEmit -p tsconfig.json" + }, + "dependencies": {}, + "devDependencies": { + "typescript": "^5.8.3" + } +} \ No newline at end of file diff --git a/packages/guides/src/index.ts b/packages/guides/src/index.ts new file mode 100644 index 000000000000..9d1599374fa6 --- /dev/null +++ b/packages/guides/src/index.ts @@ -0,0 +1 @@ +export const hello = (): string => 'Hello from @graphprotocol/guides'; \ No newline at end of file diff --git a/packages/guides/tsconfig.json b/packages/guides/tsconfig.json new file mode 100644 index 000000000000..e8ad28861afd --- /dev/null +++ b/packages/guides/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "dist", + "declaration": true, + "declarationMap": true, + "sourceMap": true + }, + "include": ["src"] +} \ No newline at end of file From c32efae8634de254ec4f68111a6393c147f7e438 Mon Sep 17 00:00:00 2001 From: Marcus Rein Date: Mon, 19 May 2025 11:09:37 -0400 Subject: [PATCH 2/4] Set up Next.js project with Tailwind CSS, add guides data and search functionality --- packages/guides/data/guides.json | 32 ++++++++ packages/guides/next-env.d.ts | 5 ++ packages/guides/next.config.js | 9 +++ packages/guides/package.json | 19 +++-- packages/guides/pages/_app.tsx | 6 ++ packages/guides/pages/guides/[slug].tsx | 19 +++++ packages/guides/pages/guides/index.tsx | 103 ++++++++++++++++++++++++ packages/guides/postcss.config.mjs | 6 ++ packages/guides/styles/globals.css | 3 + packages/guides/tailwind.config.mjs | 18 +++++ packages/guides/tsconfig.json | 17 +++- pnpm-lock.yaml | 38 ++++++++- 12 files changed, 265 insertions(+), 10 deletions(-) create mode 100644 packages/guides/data/guides.json create mode 100644 packages/guides/next-env.d.ts create mode 100644 packages/guides/next.config.js create mode 100644 packages/guides/pages/_app.tsx create mode 100644 packages/guides/pages/guides/[slug].tsx create mode 100644 packages/guides/pages/guides/index.tsx create mode 100644 packages/guides/postcss.config.mjs create mode 100644 packages/guides/styles/globals.css create mode 100644 packages/guides/tailwind.config.mjs diff --git a/packages/guides/data/guides.json b/packages/guides/data/guides.json new file mode 100644 index 000000000000..ff2c78639e33 --- /dev/null +++ b/packages/guides/data/guides.json @@ -0,0 +1,32 @@ +[ + { + "title": "Building Subgraphs 101", + "slug": "building-subgraphs-101", + "description": "Learn the basics of creating a subgraph on The Graph network.", + "categories": ["Subgraphs", "Getting Started"], + "date": "2024-05-18", + "author": "Graph Docs Team", + "types": ["blog"], + "url": "https://thegraph.com/blog/building-subgraphs-101" + }, + { + "title": "Indexing Smart Contracts with The Graph", + "slug": "indexing-smart-contracts", + "description": "Step-by-step video tutorial for indexing contracts using Graph CLI.", + "categories": ["Indexing", "Video"], + "date": "2024-03-02", + "author": "Graph Protocol", + "types": ["video"], + "url": "https://youtube.com/watch?v=dQw4w9WgXcQ" + }, + { + "title": "Using Graph Client in React", + "slug": "using-graph-client-react", + "description": "How to query subgraphs efficiently in a React front-end.", + "categories": ["Client", "React"], + "date": "2023-12-10", + "author": "Edge & Node", + "types": ["blog", "repo"], + "url": "https://github.com/graphprotocol/example" + } +] \ No newline at end of file diff --git a/packages/guides/next-env.d.ts b/packages/guides/next-env.d.ts new file mode 100644 index 000000000000..a4a7b3f5cfa2 --- /dev/null +++ b/packages/guides/next-env.d.ts @@ -0,0 +1,5 @@ +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. diff --git a/packages/guides/next.config.js b/packages/guides/next.config.js new file mode 100644 index 000000000000..deb4656b3b05 --- /dev/null +++ b/packages/guides/next.config.js @@ -0,0 +1,9 @@ +// @ts-check + +/** @type {import('next').NextConfig} */ +const nextConfig = { + reactStrictMode: true, + trailingSlash: true, +}; + +export default nextConfig; \ No newline at end of file diff --git a/packages/guides/package.json b/packages/guides/package.json index 17d732d05865..c8b6421e8c6b 100644 --- a/packages/guides/package.json +++ b/packages/guides/package.json @@ -6,12 +6,21 @@ "types": "dist/index.d.ts", "files": ["dist"], "scripts": { - "build": "tsc -p tsconfig.json", - "dev": "tsc -w -p tsconfig.json", - "typecheck": "tsc --noEmit -p tsconfig.json" + "dev": "next dev -p 3100", + "build": "next build", + "preview": "next start -p 3100", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "next": "^14.2.28", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "fuse.js": "^7.0.0" }, - "dependencies": {}, "devDependencies": { - "typescript": "^5.8.3" + "typescript": "^5.8.3", + "tailwindcss": "^3.4.17", + "postcss": "^8.5.3", + "autoprefixer": "^10.4.21" } } \ No newline at end of file diff --git a/packages/guides/pages/_app.tsx b/packages/guides/pages/_app.tsx new file mode 100644 index 000000000000..6c42fd075e7c --- /dev/null +++ b/packages/guides/pages/_app.tsx @@ -0,0 +1,6 @@ +import '@/styles/globals.css'; +import type { AppProps } from 'next/app'; + +export default function App({ Component, pageProps }: AppProps) { + return ; +} \ No newline at end of file diff --git a/packages/guides/pages/guides/[slug].tsx b/packages/guides/pages/guides/[slug].tsx new file mode 100644 index 000000000000..dbd8bdbd7848 --- /dev/null +++ b/packages/guides/pages/guides/[slug].tsx @@ -0,0 +1,19 @@ +import { GetServerSideProps } from 'next'; +import guides from '@/data/guides.json'; + +export const getServerSideProps: GetServerSideProps = async ({ params }) => { + const guide = (guides as any[]).find((g) => g.slug === params?.slug); + if (guide) { + return { + redirect: { + destination: guide.url, + permanent: false, + }, + }; + } + return { notFound: true }; +}; + +export default function Guide() { + return null; +} \ No newline at end of file diff --git a/packages/guides/pages/guides/index.tsx b/packages/guides/pages/guides/index.tsx new file mode 100644 index 000000000000..1022adc3713f --- /dev/null +++ b/packages/guides/pages/guides/index.tsx @@ -0,0 +1,103 @@ +import { useMemo, useState } from 'react'; +import Fuse from 'fuse.js'; +import guidesData from '@/data/guides.json'; +import Link from 'next/link'; + +interface Guide { + title: string; + slug: string; + description: string; + categories: string[]; + date: string; + author: string; + types: string[]; + url: string; +} + +const fuse = new Fuse(guidesData as Guide[], { + includeScore: true, + threshold: 0.4, + keys: ['title', 'description', 'categories', 'types'], +}); + +const allCategories = Array.from( + new Set((guidesData as Guide[]).flatMap((g) => g.categories)), +).sort(); + +export default function GuidesPage() { + const [query, setQuery] = useState(''); + const [selected, setSelected] = useState>(new Set()); + + const guides = useMemo(() => { + let filtered: Guide[] = guidesData as Guide[]; + if (selected.size) { + filtered = filtered.filter((g) => g.categories.some((c) => selected.has(c))); + } + if (query.trim()) { + return fuse.search(query).map((r) => r.item).filter((g) => filtered.includes(g)); + } + return filtered; + }, [query, selected]); + + const toggleCategory = (cat: string) => { + const next = new Set(selected); + if (next.has(cat)) next.delete(cat); + else next.add(cat); + setSelected(next); + }; + + return ( +
+ +
+
+ setQuery(e.target.value)} + className="w-full md:w-1/2 border rounded px-3 py-2" + /> +
+
    + {guides.map((g) => ( +
  • + +

    {g.title}

    + +

    {g.description}

    +
    + {g.categories.map((c) => ( + + {c} + + ))} + {g.types.map((t) => ( + + {t} + + ))} + {new Date(g.date).toLocaleDateString()} +
    +
  • + ))} +
+
+
+ ); +} \ No newline at end of file diff --git a/packages/guides/postcss.config.mjs b/packages/guides/postcss.config.mjs new file mode 100644 index 000000000000..a99a89c7ea64 --- /dev/null +++ b/packages/guides/postcss.config.mjs @@ -0,0 +1,6 @@ +export default { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +}; \ No newline at end of file diff --git a/packages/guides/styles/globals.css b/packages/guides/styles/globals.css new file mode 100644 index 000000000000..de4d11a2e835 --- /dev/null +++ b/packages/guides/styles/globals.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; \ No newline at end of file diff --git a/packages/guides/tailwind.config.mjs b/packages/guides/tailwind.config.mjs new file mode 100644 index 000000000000..9383acb16d7e --- /dev/null +++ b/packages/guides/tailwind.config.mjs @@ -0,0 +1,18 @@ +import defaultTheme from 'tailwindcss/defaultTheme'; + +/** @type {import('tailwindcss').Config} */ +export default { + content: [ + './pages/**/*.{js,ts,jsx,tsx}', + './components/**/*.{js,ts,jsx,tsx}', + './app/**/*.{js,ts,jsx,tsx}', + ], + theme: { + extend: { + fontFamily: { + sans: ['Inter', ...defaultTheme.fontFamily.sans], + }, + }, + }, + plugins: [], +}; \ No newline at end of file diff --git a/packages/guides/tsconfig.json b/packages/guides/tsconfig.json index e8ad28861afd..acde69463acb 100644 --- a/packages/guides/tsconfig.json +++ b/packages/guides/tsconfig.json @@ -5,7 +5,18 @@ "outDir": "dist", "declaration": true, "declarationMap": true, - "sourceMap": true + "sourceMap": true, + "baseUrl": ".", + "paths": { + "@/*": [ + "*" + ] + }, + "resolveJsonModule": true, + "jsx": "preserve", + "module": "ESNext" }, - "include": ["src"] -} \ No newline at end of file + "include": [ + "src" + ] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3109a1fa0ab3..55ebbe9f5309 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,6 +51,34 @@ importers: specifier: ^5.8.3 version: 5.8.3 + packages/guides: + dependencies: + fuse.js: + specifier: ^7.0.0 + version: 7.1.0 + next: + specifier: ^14.2.28 + version: 14.2.28(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + react: + specifier: ^18.3.1 + version: 18.3.1 + react-dom: + specifier: ^18.3.1 + version: 18.3.1(react@18.3.1) + devDependencies: + autoprefixer: + specifier: ^10.4.21 + version: 10.4.21(postcss@8.5.3) + postcss: + specifier: ^8.5.3 + version: 8.5.3 + tailwindcss: + specifier: ^3.4.17 + version: 3.4.17 + typescript: + specifier: ^5.8.3 + version: 5.8.3 + packages/og-image: dependencies: '@resvg/resvg-wasm': @@ -5322,6 +5350,10 @@ packages: functions-have-names@1.2.3: resolution: {integrity: sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==} + fuse.js@7.1.0: + resolution: {integrity: sha512-trLf4SzuuUxfusZADLINj+dE8clK1frKdmqiJNb1Es75fmI5oY6X2mxLVUciLLjxqw/xr72Dhy+lER6dGd02FQ==} + engines: {node: '>=10'} + get-caller-file@2.0.5: resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} engines: {node: 6.* || 8.* || >= 10.*} @@ -15435,6 +15467,8 @@ snapshots: functions-have-names@1.2.3: {} + fuse.js@7.1.0: {} + get-caller-file@2.0.5: {} get-intrinsic@1.3.0: @@ -17440,8 +17474,8 @@ snapshots: ox@0.6.9(typescript@5.8.3)(zod@3.24.3): dependencies: '@adraffy/ens-normalize': 1.11.0 - '@noble/curves': 1.8.2 - '@noble/hashes': 1.7.2 + '@noble/curves': 1.9.0 + '@noble/hashes': 1.8.0 '@scure/bip32': 1.6.2 '@scure/bip39': 1.5.4 abitype: 1.0.8(typescript@5.8.3)(zod@3.24.3) From c48f662077d754a0fd9c3ac26d20497d0a8a61fd Mon Sep 17 00:00:00 2001 From: Marcus Rein Date: Mon, 19 May 2025 11:24:26 -0400 Subject: [PATCH 3/4] Refactor guide page to use static generation; enhance guide data structure with additional fields --- packages/guides/data/guides.json | 131 ++++++++++++++++++++++-- packages/guides/pages/guides/[slug].tsx | 70 ++++++++++--- packages/guides/pages/guides/index.tsx | 116 ++++++++++++++------- 3 files changed, 258 insertions(+), 59 deletions(-) diff --git a/packages/guides/data/guides.json b/packages/guides/data/guides.json index ff2c78639e33..9f7367ecef4c 100644 --- a/packages/guides/data/guides.json +++ b/packages/guides/data/guides.json @@ -3,30 +3,143 @@ "title": "Building Subgraphs 101", "slug": "building-subgraphs-101", "description": "Learn the basics of creating a subgraph on The Graph network.", - "categories": ["Subgraphs", "Getting Started"], + "products": ["Subgraphs", "The Graph Network"], "date": "2024-05-18", "author": "Graph Docs Team", - "types": ["blog"], - "url": "https://thegraph.com/blog/building-subgraphs-101" + "types": ["Blog"], + "difficulty": "Easy", + "content": "# Building Subgraphs 101\n\nThis is a stub page for the guide content..." }, { "title": "Indexing Smart Contracts with The Graph", "slug": "indexing-smart-contracts", "description": "Step-by-step video tutorial for indexing contracts using Graph CLI.", - "categories": ["Indexing", "Video"], + "products": ["Graph Node", "Subgraphs"], "date": "2024-03-02", "author": "Graph Protocol", - "types": ["video"], - "url": "https://youtube.com/watch?v=dQw4w9WgXcQ" + "types": ["Video", "Workshop"], + "difficulty": "Intermediate", + "content": "# Indexing Smart Contracts with The Graph\nVideo embed or details here..." }, { "title": "Using Graph Client in React", "slug": "using-graph-client-react", "description": "How to query subgraphs efficiently in a React front-end.", - "categories": ["Client", "React"], + "products": ["Token API", "Subgraphs"], "date": "2023-12-10", "author": "Edge & Node", - "types": ["blog", "repo"], - "url": "https://github.com/graphprotocol/example" + "types": ["Blog", "Repository"], + "difficulty": "Easy", + "content": "# Using Graph Client in React\nContent placeholder." + }, + { + "title": "Substreams Rust Workshop", + "slug": "substreams-rust-workshop", + "description": "Hands-on workshop on authoring Substreams modules in Rust.", + "products": ["Substreams"], + "date": "2024-01-15", + "author": "StreamingFast", + "types": ["Workshop", "Video"], + "difficulty": "Advanced", + "content": "# Substreams Rust Workshop\nContent stub." + }, + { + "title": "Deploying Graph Node on Kubernetes", + "slug": "deploying-graph-node-k8s", + "description": "Guide to deploy an indexing node on Kubernetes cluster.", + "products": ["Graph Node", "The Graph Network"], + "date": "2024-02-20", + "author": "Graph Community", + "types": ["Blog"], + "difficulty": "Advanced", + "content": "# Deploying Graph Node on Kubernetes\nStub article." + }, + { + "title": "Building Token API Queries", + "slug": "building-token-api-queries", + "description": "Learn to query token metadata using The Graph Token API.", + "products": ["Token API"], + "date": "2024-04-02", + "author": "Graph Docs Team", + "types": ["Blog"], + "difficulty": "Intermediate", + "content": "# Building Token API Queries\nStub." + }, + { + "title": "Intro to The Graph Network", + "slug": "intro-graph-network", + "description": "High-level overview of how the decentralized network works.", + "products": ["The Graph Network"], + "date": "2023-11-05", + "author": "Graph Foundation", + "types": ["Video"], + "difficulty": "Easy", + "content": "# Intro to The Graph Network\nStub." + }, + { + "title": "Optimizing Subgraph Performance", + "slug": "optimizing-subgraph-performance", + "description": "Best practices for faster indexing and query responses.", + "products": ["Subgraphs"], + "date": "2024-05-01", + "author": "Edge & Node", + "types": ["Blog"], + "difficulty": "Intermediate", + "content": "# Optimizing Subgraph Performance\nStub." + }, + { + "title": "GraphQL Basics for The Graph", + "slug": "graphql-basics", + "description": "Essential GraphQL concepts every Graph builder should know.", + "products": ["Subgraphs", "Token API"], + "date": "2023-10-01", + "author": "Graph Docs Team", + "types": ["Blog", "Video"], + "difficulty": "Easy", + "content": "# GraphQL Basics\nStub." + }, + { + "title": "Migrating from Hosted Service to Network", + "slug": "migrating-to-network", + "description": "Step-by-step migration strategy.", + "products": ["The Graph Network", "Subgraphs"], + "date": "2024-06-10", + "author": "Graph Ops", + "types": ["Blog", "Workshop"], + "difficulty": "Advanced", + "content": "# Migration Guide\nStub." + }, + { + "title": "Query Token Prices Using Substreams", + "slug": "token-prices-substreams", + "description": "Create a Substreams pipeline for token price data.", + "products": ["Substreams", "Token API"], + "date": "2024-04-25", + "author": "StreamingFast", + "types": ["Repository"], + "difficulty": "Intermediate", + "content": "# Token Prices Substreams\nStub." + }, + { + "title": "Graph Node Metrics and Monitoring", + "slug": "graph-node-metrics", + "description": "Expose Prometheus metrics from Graph Node and set up Grafana dashboards.", + "products": ["Graph Node"], + "date": "2024-02-28", + "author": "Graph Community", + "types": ["Blog", "Repository"], + "difficulty": "Advanced", + "content": "# Graph Node Metrics\nStub." + }, + { + "title": "Deploying a Subgraph on Arbitrum", + "slug": "deploying-subgraph-arbitrum", + "description": "End-to-end guide to deploy a subgraph for Arbitrum network.", + "products": ["Subgraphs"], + "date": "2024-05-30", + "author": "Graph Docs Team", + "types": ["Blog"], + "difficulty": "Intermediate", + "content": "# Deploying Subgraph on Arbitrum\nStub." } ] \ No newline at end of file diff --git a/packages/guides/pages/guides/[slug].tsx b/packages/guides/pages/guides/[slug].tsx index dbd8bdbd7848..8ea0f97ae79e 100644 --- a/packages/guides/pages/guides/[slug].tsx +++ b/packages/guides/pages/guides/[slug].tsx @@ -1,19 +1,59 @@ -import { GetServerSideProps } from 'next'; -import guides from '@/data/guides.json'; +import { GetStaticPaths, GetStaticProps } from 'next'; +import Link from 'next/link'; +import guides from '../../data/guides.json'; -export const getServerSideProps: GetServerSideProps = async ({ params }) => { - const guide = (guides as any[]).find((g) => g.slug === params?.slug); - if (guide) { - return { - redirect: { - destination: guide.url, - permanent: false, - }, - }; - } - return { notFound: true }; +interface Guide { + title: string; + slug: string; + description: string; + products: string[]; + date: string; + author: string; + types: string[]; + difficulty: string; + content: string; + url?: string; +} + +export const getStaticPaths: GetStaticPaths = async () => { + return { + paths: (guides as Guide[]).map((g) => ({ params: { slug: g.slug } })), + fallback: false, + }; +}; + +export const getStaticProps: GetStaticProps = async ({ params }) => { + const guide = (guides as Guide[]).find((g) => g.slug === params?.slug); + if (!guide) return { notFound: true }; + return { + props: { guide }, + }; }; -export default function Guide() { - return null; +export default function GuidePage({ guide }: { guide: Guide }) { + return ( +
+ ← Back to Guides +

{guide.title}

+

{guide.description}

+
+ {guide.products.map((p) => ( + {p} + ))} + {guide.types.map((t) => ( + {t} + ))} + {guide.difficulty} + {new Date(guide.date).toLocaleDateString()} +
+
') }} /> + {guide.url && ( +

+ + View original resource + +

+ )} +
+ ); } \ No newline at end of file diff --git a/packages/guides/pages/guides/index.tsx b/packages/guides/pages/guides/index.tsx index 1022adc3713f..3d1babad6c2e 100644 --- a/packages/guides/pages/guides/index.tsx +++ b/packages/guides/pages/guides/index.tsx @@ -1,68 +1,113 @@ -import { useMemo, useState } from 'react'; +import React, { useMemo, useState } from 'react'; import Fuse from 'fuse.js'; -import guidesData from '@/data/guides.json'; +import guidesData from '../../data/guides.json'; import Link from 'next/link'; interface Guide { title: string; slug: string; description: string; - categories: string[]; + products: string[]; date: string; author: string; types: string[]; - url: string; + url?: string; + difficulty: string; + content: string; } +const PRODUCTS = [ + 'Subgraphs', + 'Substreams', + 'Token API', + 'The Graph Network', + 'Graph Node', +] as const; + +const GUIDE_TYPES = ['Blog', 'Repository', 'Video', 'Workshop'] as const; + +const DIFFICULTIES = ['Easy', 'Intermediate', 'Advanced'] as const; + const fuse = new Fuse(guidesData as Guide[], { includeScore: true, threshold: 0.4, - keys: ['title', 'description', 'categories', 'types'], + keys: ['title', 'description', 'products', 'types'], }); -const allCategories = Array.from( - new Set((guidesData as Guide[]).flatMap((g) => g.categories)), -).sort(); - export default function GuidesPage() { const [query, setQuery] = useState(''); - const [selected, setSelected] = useState>(new Set()); + const [selectedProducts, setSelectedProducts] = useState>(new Set()); + const [selectedTypes, setSelectedTypes] = useState>(new Set()); + const [selectedDifficulties, setSelectedDifficulties] = useState>(new Set()); const guides = useMemo(() => { let filtered: Guide[] = guidesData as Guide[]; - if (selected.size) { - filtered = filtered.filter((g) => g.categories.some((c) => selected.has(c))); + + if (selectedProducts.size) { + filtered = filtered.filter((g) => g.products.some((p) => selectedProducts.has(p))); + } + if (selectedTypes.size) { + filtered = filtered.filter((g) => g.types.some((t) => selectedTypes.has(t))); + } + if (selectedDifficulties.size) { + filtered = filtered.filter((g) => selectedDifficulties.has(g.difficulty)); } if (query.trim()) { - return fuse.search(query).map((r) => r.item).filter((g) => filtered.includes(g)); + return fuse + .search(query) + .map((r) => r.item) + .filter((g) => filtered.includes(g)); } return filtered; - }, [query, selected]); + }, [query, selectedProducts, selectedTypes, selectedDifficulties]); - const toggleCategory = (cat: string) => { - const next = new Set(selected); - if (next.has(cat)) next.delete(cat); - else next.add(cat); - setSelected(next); + const toggle = (value: string, set: React.Dispatch>>) => { + set((prev) => { + const next = new Set(prev); + next.has(value) ? next.delete(value) : next.add(value); + return next; + }); }; + const Checkbox = ({ label, checked, onChange }: { label: string; checked: boolean; onChange(): void }) => ( +
  • + + {label} +
  • + ); + return (
    -