// Dependencies
import orderBy from 'lodash.orderby'
import { capitalize } from 'shared/utils.mjs'
import { siteConfig } from 'site/site.config.mjs'
import { freeSewingConfig as conf } from 'shared/config/freesewing.config.mjs'
import { measurements, isDegreeMeasurement } from 'config/measurements.mjs'
// Context
import { LoadingContext } from 'shared/context/loading-context.mjs'
import { ModalContext } from 'shared/context/modal-context.mjs'
import { NavigationContext } from 'shared/context/navigation-context.mjs'
// Hooks
import { useState, useEffect, useContext } from 'react'
import { useTranslation } from 'next-i18next'
import { useAccount } from 'shared/hooks/use-account.mjs'
import { useBackend } from 'shared/hooks/use-backend.mjs'
import { useToast } from 'shared/hooks/use-toast.mjs'
// Components
import Link from 'next/link'
import { PopoutWrapper } from 'shared/components/wrappers/popout.mjs'
import { Collapse, useCollapseButton } from 'shared/components/collapse.mjs'
import { ClearIcon, TrashIcon, EditIcon, FilterIcon } from 'shared/components/icons.mjs'
import { ModalWrapper } from 'shared/components/wrappers/modal.mjs'
import Timeago from 'react-timeago'
import { Tag } from 'shared/components/tag.mjs'
import { Row } from './index.mjs'
import { PageLink } from 'shared/components/page-link.mjs'
import { EditRow, MeasieRow } from 'shared/components/account/sets.mjs'
export const ns = ['toast', 'curate', 'sets', 'account']
const EditImg = ({ set, t }) => {
return (
,
]}
>
)
}
const EditName = ({ set, t, lang }) => {
return (
{`${t('name')} (${lang.toUpperCase()})`}
{set[`name${capitalize(lang)}`]}
}
primary
buttons={[
,
]}
>
{set[`name${capitalize(lang)}`]}
)
}
const EditNotes = ({ set, t, lang }) => {
return (
{`${t('notes')} (${lang.toUpperCase()})`}}
primary
buttons={[
,
]}
>
{set[`name${capitalize(lang)}`]}
)
}
const EditTags = ({ set, t, lang }) => {
return (
{`${t('tags')} (${lang.toUpperCase()})`}}
primary
buttons={[
,
]}
>
{set[`name${capitalize(lang)}`]}
)
}
export const EditCuratedSet = ({ id }) => {
// Context
const { startLoading, stopLoading } = useContext(LoadingContext)
const { setNavigation } = useContext(NavigationContext)
// Hooks
const { account, token } = useAccount()
const backend = useBackend(token)
const { t, i18n } = useTranslation('sets', 'curate', 'toast', 'account')
const { language } = i18n
const toast = useToast()
// State
const [set, setSet] = useState([])
const [reload, setReload] = useState(0)
const [filter, setFilter] = useState(false)
// Force a refresh
const refresh = () => setReload(reload + 1)
// Effects
useEffect(() => {
const getCuratedSet = async () => {
const result = await backend.getCuratedSet(id)
if (result.success) {
setSet(result.data.curatedSet)
}
}
getCuratedSet()
}, [reload])
const editProps = {
startLoading,
stopLoading,
account,
backend,
t,
toast,
mset: set,
curated: true,
}
const filterMeasurements = () => {
if (!filter) return measurements.map((m) => t(`measurements:${m}`)).sort()
else return designMeasurements[filter].map((m) => t(`measurements:${m}`)).sort()
}
return (
{/* Meta info */}
{account.control > 2 ? (
{t('created')}:
{t('updated')}:
) : null}
{/* JSON & YAML links */}
{account.control > 3 ? (
) : null}
{t('account:data')}
{/* img: Control level determines whether or not to show this */}
{account.control >= conf.account.sets.img ? (
) : null}
{/* Name is always shown */}
{siteConfig.languages.map((lang) => (
{set[`name${capitalize(lang)}`]}
))}
{/* Notes are always shown */}
{account.control >= conf.account.sets.notes
? siteConfig.languages.map((lang) => (
{set[`notes${capitalize(lang)}`]}
))
: null}
{t('account:measies')}
{filterMeasurements().map((m) => (
))}
)
}