// Dependencies import { atomWithHash } from 'jotai-location' import { about, collection, tags, techniques, designers, developers, examples, } from '@freesewing/collection' import { mutateObject } from '@freesewing/utils' //import { urls } from '@freesewing/config' //import { measurements as measurementTranslations } from '@freesewing/i18n' //import { measurements as designMeasurements } from '@freesewing/collection' // Context //import { LoadingStatusContext } from '@freesewing/react/context/LoadingStatus' import { ModalContext } from '@freesewing/react/context/Modal' // Hooks import React, { useState, useContext } from 'react' //import { useAccount } from '@freesewing/react/hooks/useAccount' //import { useBackend } from '@freesewing/react/hooks/useBackend' import { useAtom } from 'jotai' // Components import { Link as WebLink, AnchorLink } from '@freesewing/react/components/Link' import { CircleIcon, CisFemaleIcon, FilterIcon, ResetIcon, ShowcaseIcon, } from '@freesewing/react/components/Icon' import { lineDrawingsFront as lineDrawings } from '@freesewing/react/components/LineDrawing' /* 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 { 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) } /** * React component to show the FreeSewing collection and pick a design * * @param {object} props - All React props * @param {function} Link - An optional framework specific Link component for client-side routing */ export const Collection = ({ Link = false, linkTo = 'about' }) => { if (!Link) Link = WebLink // State const [filter, setFilter] = useFilter() const [showFilters, setShowFilters] = useState(false) console.log(tags) /* * Apply filter */ const filtered = {} for (const d of collection) { let skip = false if ( filter.tag && filter.tag.filter((tag) => about[d].tags.includes(tag)).length < filter.tag.length ) skip = true if ( filter.tech && filter.tech.filter((tech) => about[d].techniques.includes(tech)).length < filter.tech.length ) skip = true if (filter.difficulty && filter.difficulty !== about[d].difficulty) skip = true if (!skip) filtered[d] = d } const updateFilter = (path, val) => { // Allow clicking the same difficulty to remove it as a filter if (path === 'difficulty' && val === filter.difficulty) val = 'unset' const newFilter = mutateObject({ ...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 ( <>