// Dependencies
import { useState, useEffect, useContext } from 'react'
import { useTranslation } from 'next-i18next'
import { freeSewingConfig as conf, controlLevels } from 'shared/config/freesewing.config.mjs'
import { shortDate, cloudflareImageUrl, capitalize } from 'shared/utils.mjs'
//import orderBy from 'lodash.orderby'
// Hooks
import { useAccount } from 'shared/hooks/use-account.mjs'
import { useBackend } from 'shared/hooks/use-backend.mjs'
// Context
import { ModalContext } from 'shared/context/modal-context.mjs'
import { LoadingStatusContext } from 'shared/context/loading-status-context.mjs'
// Components
import { DisplayRow } from './account/shared.mjs'
import { ModalWrapper } from 'shared/components/wrappers/modal.mjs'
import Markdown from 'react-markdown'
import Timeago from 'react-timeago'
import { MeasieVal } from './account/sets.mjs'
import { CameraIcon } from 'shared/components/icons.mjs'
export const ns = ['account', 'patterns', 'status', 'measurements', 'sets']
const SetLineup = ({ sets = [], onClick = false }) => (
1 ? 'justify-start px-8' : 'justify-center'
} overflow-x-scroll`}
style={{
backgroundImage: `url(/img/lineup-backdrop.svg)`,
width: 'auto',
backgroundSize: 'auto 100%',
backgroundRepeat: 'repeat-x',
}}
>
{sets.map((set) => {
const props = {
className: 'aspect-[1/3] w-auto h-96',
style: {
backgroundImage: `url(${cloudflareImageUrl({ id: set.img, type: 'lineup' })})`,
width: 'auto',
backgroundSize: 'contain',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
},
}
if (onClick) props.onClick = () => onClick(set.id)
if (onClick) return
else return
})}
)
const ShowCuratedSet = ({ cset }) => {
const { control } = useAccount()
const { t, i18n } = useTranslation(ns)
const lang = i18n.language
const { setModal } = useContext(ModalContext)
if (!cset) return null
return (
<>
{cset[`name${capitalize(lang)}`]}
{control > 3 && (
<>
JSON
YAML
>
)}
{t('data')}
{cset[`name${capitalize(lang)}`]}
{control >= controlLevels.sets.notes && (
{cset[`notes${capitalize(lang)}`]}
)}
{control >= controlLevels.sets.createdAt && (
|
{shortDate(i18n.language, cset.createdAt, false)}
)}
{control >= controlLevels.sets.updatedAt && (
|
{shortDate(i18n.language, cset.updatedAt, false)}
)}
{control >= controlLevels.sets.id && {cset.id}}
{t('measies')}
{Object.entries(cset.measies).map(([m, val]) =>
val > 0 ? (
} key={m}>
{t(m)}
) : null
)}
>
)
}
export const CuratedSet = ({ id }) => {
// Hooks
const { setLoadingStatus } = useContext(LoadingStatusContext)
const backend = useBackend()
// State
const [cset, setCset] = useState()
// Effect
useEffect(() => {
const getCset = async () => {
setLoadingStatus([true, 'status:contactingBackend'])
const result = await backend.getCuratedSet(id)
if (result.success) {
setCset(result.data.curatedSet)
setLoadingStatus([true, 'status:dataLoaded', true, true])
} else setLoadingStatus([true, 'status:backendError', true, false])
}
if (id) getCset()
}, [id])
if (!id || !cset) return null
return (
)
}
// Component for the curated-sets page
export const CuratedSets = () => {
// Hooks
const backend = useBackend()
const { setLoadingStatus } = useContext(LoadingStatusContext)
// State
const [sets, setSets] = useState([])
const [selected, setSelected] = useState(false)
// Effects
useEffect(() => {
const getSets = async () => {
setLoadingStatus([true, 'contactingBackend'])
const result = await backend.getCuratedSets()
if (result.success) {
const allSets = {}
for (const set of result.data.curatedSets) allSets[set.id] = set
setSets(allSets)
setLoadingStatus([true, 'status:dataLoaded', true, true])
} else setLoadingStatus([true, 'status:backendError', true, false])
}
getSets()
}, [])
return (
{selected && }
)
}