-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app/filters): allow filter on variant tags
This patch adds some nested variant filters. In addition to filtering by a variant's colors, users can now filter on a variant's tags. This probably requires some polish to automatically support new nested fields as they come, or, just make it less hacky and more explicit from the get-go (e.g. specifying which fields can be filtered on upfront).
- Loading branch information
1 parent
4e17b55
commit 0ef6db8
Showing
4 changed files
with
237 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Link, useLoaderData } from '@remix-run/react' | ||
import { type LoaderFunctionArgs } from '@vercel/remix' | ||
|
||
import { ListLayout } from 'components/list-layout' | ||
|
||
import { getTagFilter, getTagName } from 'utils/variant' | ||
|
||
import { prisma } from 'db.server' | ||
import { FILTER_PARAM, filterToSearchParam, getSearch } from 'filters' | ||
import { log } from 'log.server' | ||
|
||
export async function loader({ request }: LoaderFunctionArgs) { | ||
log.debug('getting tags...') | ||
const search = getSearch(request) | ||
const tags = await prisma.tag.findMany({ | ||
take: 100, | ||
where: search ? { name: { search } } : undefined, | ||
}) | ||
log.debug('got %d tags', tags.length) | ||
return tags | ||
} | ||
|
||
export default function TagsPage() { | ||
const tags = useLoaderData<typeof loader>() | ||
return ( | ||
<ListLayout title='variants'> | ||
{tags.map((tag) => { | ||
const param = filterToSearchParam<'variants', 'some'>(getTagFilter(tag)) | ||
return ( | ||
<li key={tag.id}> | ||
<Link | ||
prefetch='intent' | ||
className='link underline' | ||
to={`/products?${FILTER_PARAM}=${encodeURIComponent(param)}`} | ||
> | ||
{getTagName(tag)} | ||
</Link> | ||
</li> | ||
) | ||
})} | ||
</ListLayout> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters