// Dependencies
import { orderBy, cloudflareImageUrl, getSearchParam, formatMm } from '@freesewing/utils'
import { isDegreeMeasurement } from '@freesewing/config'
import { measurements as measurementTranslations } from '@freesewing/i18n'
// Hooks
import { useBackend } from '@freesewing/react/hooks/useBackend'
import React, { useState, useEffect } from 'react'
// Components
import { Link as WebLink } from '@freesewing/react/components/Link'
import { MiniWarning } from '@freesewing/react/components/Mini'
import { Spinner } from '@freesewing/react/components/Spinner'
import { Markdown } from '@freesewing/react/components/Markdown'
import { KeyVal } from '@freesewing/react/components/KeyVal'
/**
* A component to render a lineup of curated measurements sets.
*
* You need to provide either a clickHandler or a method to resolve the URL to link to as the href prop.
*
* @component
* @param {object} props - All component props
* @param {React.Component} props.Link - A framework specific Link component for client-side routing
* @param {function} [props.clickHandler = false] - An optional function to call when a set is clicked
* @param {function} [props.href = false] - An optional function that should return the URL to be used for a given set
* @returns {JSX.Element}
*/
export const CuratedSetLineup = ({ href = false, clickHandler = false, Link = false }) => {
if (!Link) Link = WebLink
// Hooks
const backend = useBackend()
// State (local)
const [sets, setSets] = useState([])
// Effects
useEffect(() => {
const getSets = async () => {
const [status, body] = await backend.getCuratedSets()
if (status === 200 && body.result === 'success') {
const allSets = []
for (const set of body.curatedSets) {
if (set.published) allSets.push(set)
}
setSets(orderBy(allSets, 'height', 'asc'))
}
}
getSets()
}, [])
if (!href && !clickHandler)
return (
href
or clickHandler
prop to the{' '}
CuratedSetLineup
component.
Measurement | Metric | Imperial |
---|---|---|
{entry.t} | {isDegreeMeasurement(entry.id) ? `${entry.val}°` : formatMm(entry.val)} |