Template
Add product search with autocomplete, filters, and sort
- Header: search button opening a command-palette dialog with debounced product suggestions, a term chip, and View All - Command: shadcn-shaped primitives built on the project's own Dialog so no cmdk/radix dependency is introduced - /search: results grid with item count, sort (relevance, price asc/desc), and cursor-based load more - Filters: driven by the API's productFilters facets — colour swatches, labelled lists with counts, and a price range — round-tripped through each facet's raw input string so no filter shape is hardcoded Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016jWbNNJLksC1QG8z8845FX
This commit is contained in:
co-authored by
Claude Opus 5
parent
e04f1e0405
commit
cc901b9ce8
@@ -0,0 +1,79 @@
|
||||
import { ProductFragment } from '@/graphql/products';
|
||||
|
||||
// Storefront search over products. `productFilters` accepts the raw `input`
|
||||
// values returned in `productFilters[].values[].input`, so facets round-trip
|
||||
// without the client needing to know each filter's shape.
|
||||
export const SEARCH_PRODUCTS_QUERY = `
|
||||
${ProductFragment}
|
||||
query SearchProducts(
|
||||
$query: String!
|
||||
$first: Int!
|
||||
$after: String
|
||||
$sortKey: SearchSortKeys
|
||||
$reverse: Boolean
|
||||
$productFilters: [ProductFilter!]
|
||||
) {
|
||||
search(
|
||||
query: $query
|
||||
first: $first
|
||||
after: $after
|
||||
types: PRODUCT
|
||||
sortKey: $sortKey
|
||||
reverse: $reverse
|
||||
productFilters: $productFilters
|
||||
) {
|
||||
totalCount
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
productFilters {
|
||||
id
|
||||
label
|
||||
type
|
||||
values {
|
||||
id
|
||||
label
|
||||
count
|
||||
input
|
||||
}
|
||||
}
|
||||
edges {
|
||||
node {
|
||||
... on Product {
|
||||
...ProductFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
// Lightweight variant for the autocomplete dropdown — just enough to render a
|
||||
// row, so the dialog stays responsive while typing.
|
||||
export const SEARCH_SUGGESTIONS_QUERY = `
|
||||
query SearchSuggestions($query: String!, $first: Int!) {
|
||||
search(query: $query, first: $first, types: PRODUCT) {
|
||||
totalCount
|
||||
edges {
|
||||
node {
|
||||
... on Product {
|
||||
id
|
||||
title
|
||||
handle
|
||||
featuredImage {
|
||||
url
|
||||
altText
|
||||
}
|
||||
priceRange {
|
||||
minVariantPrice {
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
Reference in New Issue
Block a user