import { designs, tags, techniques } from 'shared/config/designs.mjs' import { DesignCard, DesignLink, ns as designNs } from 'shared/components/designs/design.mjs' import { useTranslation } from 'next-i18next' import { useState } from 'react' import { FilterIcon, ShowcaseIcon, CisFemaleIcon, ResetIcon } from 'shared/components/icons.mjs' import { useAtom } from 'jotai' import { atomWithHash } from 'jotai-location' import { capitalize, objUpdate } from 'shared/utils.mjs' import { Difficulty } from 'shared/components/designs/difficulty.mjs' import { collection } from 'site/hooks/use-design.mjs' export const ns = designNs const filterAtom = atomWithHash('filter', { example: true }) export const useFilter = () => { return useAtom(filterAtom) } export const DesignPicker = ({ linkTo = 'new', altLinkTo = 'docs' }) => { const { t } = useTranslation('designs') const [filter, setFilter] = useFilter() const [showFilters, setShowFilters] = useState(false) // Need to sort designs by their translated title // let's also apply the filters while we're at it const translated = {} for (const d of collection) { let skip = false if ( filter.tag && filter.tag.filter((tag) => designs[d].tags.includes(tag)).length < filter.tag.length ) skip = true if ( filter.tech && filter.tech.filter((tech) => designs[d].techniques.includes(tech)).length < filter.tech.length ) skip = true if (filter.difficulty && filter.difficulty !== designs[d].difficulty) skip = true if (!skip) translated[t(`${d}.t`)] = d } const updateFilter = (path, val) => { const newFilter = objUpdate({ ...filter }, path, val) setFilter(newFilter) } const toggle = (type, val) => { const current = filter[type] || [] const newSet = new Set(current) if (newSet.has(val)) newSet.delete(val) else newSet.add(val) updateFilter(type, [...newSet]) } return ( <>