2023-09-29 18:20:28 +02:00
|
|
|
// __SDEFILE__ - This file is a dependency for the stand-alone environment
|
2023-04-22 16:41:13 +02:00
|
|
|
// Dependencies
|
2023-06-22 11:29:19 -05:00
|
|
|
import { measurements } from 'config/measurements.mjs'
|
2023-05-17 17:32:19 +02:00
|
|
|
import { measurements as designMeasurements } from 'shared/prebuild/data/design-measurements.mjs'
|
2023-08-23 17:41:34 +02:00
|
|
|
import { freeSewingConfig as conf, controlLevels } from 'shared/config/freesewing.config.mjs'
|
2023-09-04 08:40:05 +02:00
|
|
|
import { isDegreeMeasurement } from 'config/measurements.mjs'
|
2023-08-26 16:13:11 +02:00
|
|
|
import {
|
|
|
|
shortDate,
|
|
|
|
cloudflareImageUrl,
|
|
|
|
formatMm,
|
|
|
|
hasRequiredMeasurements,
|
|
|
|
capitalize,
|
2023-08-26 18:23:22 +02:00
|
|
|
horFlexClasses,
|
2023-08-26 16:13:11 +02:00
|
|
|
} from 'shared/utils.mjs'
|
2023-04-22 16:41:13 +02:00
|
|
|
// Hooks
|
2023-09-04 08:40:05 +02:00
|
|
|
import { useState, useEffect, useContext } from 'react'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-04-22 16:41:13 +02:00
|
|
|
import { useAccount } from 'shared/hooks/use-account.mjs'
|
|
|
|
import { useBackend } from 'shared/hooks/use-backend.mjs'
|
|
|
|
import { useRouter } from 'next/router'
|
2023-04-28 21:23:06 +02:00
|
|
|
// Context
|
2023-09-04 08:40:05 +02:00
|
|
|
import { LoadingStatusContext } from 'shared/context/loading-status-context.mjs'
|
2023-04-28 21:23:06 +02:00
|
|
|
import { ModalContext } from 'shared/context/modal-context.mjs'
|
2023-04-22 16:41:13 +02:00
|
|
|
// Components
|
2023-08-26 16:13:11 +02:00
|
|
|
import { Popout } from 'shared/components/popout/index.mjs'
|
2023-08-24 18:39:12 +02:00
|
|
|
import { BackToAccountButton } from './shared.mjs'
|
2023-08-29 09:39:48 +02:00
|
|
|
import { AnchorLink, PageLink, Link } from 'shared/components/link.mjs'
|
2023-04-23 18:00:52 +02:00
|
|
|
import {
|
|
|
|
OkIcon,
|
|
|
|
NoIcon,
|
|
|
|
TrashIcon,
|
|
|
|
EditIcon,
|
2023-08-23 12:18:20 +02:00
|
|
|
UploadIcon,
|
|
|
|
ResetIcon,
|
2023-08-23 18:49:21 +02:00
|
|
|
PlusIcon,
|
2023-08-26 16:13:11 +02:00
|
|
|
WarningIcon,
|
2023-08-26 18:23:22 +02:00
|
|
|
CameraIcon,
|
2023-09-03 17:53:19 +02:00
|
|
|
CsetIcon,
|
|
|
|
BoolYesIcon,
|
|
|
|
BoolNoIcon,
|
2024-03-17 11:18:21 +01:00
|
|
|
CloneIcon,
|
2023-04-23 18:00:52 +02:00
|
|
|
} from 'shared/components/icons.mjs'
|
2023-04-22 16:41:13 +02:00
|
|
|
import { ModalWrapper } from 'shared/components/wrappers/modal.mjs'
|
2023-10-10 09:05:22 +02:00
|
|
|
import { Mdx } from 'shared/components/mdx/dynamic.mjs'
|
2023-04-23 18:00:52 +02:00
|
|
|
import Timeago from 'react-timeago'
|
2023-08-23 17:47:21 +02:00
|
|
|
import { DisplayRow } from './shared.mjs'
|
2023-08-23 12:18:20 +02:00
|
|
|
import {
|
|
|
|
StringInput,
|
|
|
|
PassiveImageInput,
|
|
|
|
ListInput,
|
|
|
|
MarkdownInput,
|
|
|
|
MeasieInput,
|
2023-08-23 17:41:34 +02:00
|
|
|
DesignDropdown,
|
|
|
|
ns as inputNs,
|
2023-08-23 12:18:20 +02:00
|
|
|
} from 'shared/components/inputs.mjs'
|
2023-09-24 12:39:25 +02:00
|
|
|
import { BookmarkButton } from 'shared/components/bookmarks.mjs'
|
2023-10-09 11:42:16 +02:00
|
|
|
import { DynamicMdx } from 'shared/components/mdx/dynamic.mjs'
|
2023-04-30 20:31:28 +02:00
|
|
|
|
2023-08-26 16:13:11 +02:00
|
|
|
export const ns = [inputNs, 'account', 'patterns', 'status', 'measurements', 'sets']
|
2023-04-28 21:23:06 +02:00
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
export const NewSet = () => {
|
2023-04-28 21:23:06 +02:00
|
|
|
// Hooks
|
2023-09-04 08:40:05 +02:00
|
|
|
const { setLoadingStatus } = useContext(LoadingStatusContext)
|
2023-08-23 12:18:20 +02:00
|
|
|
const backend = useBackend()
|
|
|
|
const { t } = useTranslation(ns)
|
2023-04-22 16:41:13 +02:00
|
|
|
const router = useRouter()
|
2024-02-22 07:20:00 -08:00
|
|
|
const { account } = useAccount()
|
2023-04-28 21:23:06 +02:00
|
|
|
|
|
|
|
// State
|
2023-04-22 16:41:13 +02:00
|
|
|
const [name, setName] = useState('')
|
|
|
|
|
2024-02-22 07:20:00 -08:00
|
|
|
// Use account setting for imperial
|
|
|
|
const imperial = account.imperial
|
|
|
|
|
2023-04-28 21:23:06 +02:00
|
|
|
// Helper method to create a new set
|
2023-04-22 16:41:13 +02:00
|
|
|
const createSet = async () => {
|
2023-08-23 12:18:20 +02:00
|
|
|
setLoadingStatus([true, 'processingUpdate'])
|
2024-02-22 07:20:00 -08:00
|
|
|
const result = await backend.createSet({ name, imperial })
|
2023-04-22 16:41:13 +02:00
|
|
|
if (result.success) {
|
2023-08-23 12:18:20 +02:00
|
|
|
setLoadingStatus([true, t('nailedIt'), true, true])
|
2023-10-22 19:13:00 +02:00
|
|
|
router.push(`/account/set?id=${result.data.set.id}`)
|
2023-08-23 12:18:20 +02:00
|
|
|
} else setLoadingStatus([true, 'backendError', true, false])
|
2023-04-22 16:41:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-08-23 12:18:20 +02:00
|
|
|
<div className="max-w-xl">
|
2023-04-30 17:50:15 +02:00
|
|
|
<h5>{t('name')}</h5>
|
2023-04-22 16:41:13 +02:00
|
|
|
<p>{t('setNameDesc')}</p>
|
|
|
|
<input
|
2023-04-23 18:00:52 +02:00
|
|
|
autoFocus
|
2023-04-22 16:41:13 +02:00
|
|
|
value={name}
|
|
|
|
onChange={(evt) => setName(evt.target.value)}
|
|
|
|
className="input w-full input-bordered flex flex-row"
|
|
|
|
type="text"
|
|
|
|
placeholder={'Georg Cantor'}
|
|
|
|
/>
|
2023-04-30 17:50:15 +02:00
|
|
|
<div className="flex flex-row gap-2 items-center w-full mt-8 mb-2">
|
2023-04-22 16:41:13 +02:00
|
|
|
<button
|
|
|
|
className="btn btn-primary grow capitalize"
|
|
|
|
disabled={name.length < 1}
|
|
|
|
onClick={createSet}
|
|
|
|
>
|
|
|
|
{t('newSet')}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
export const MeasieVal = ({ val, m, imperial }) =>
|
2023-09-12 13:52:07 +02:00
|
|
|
isDegreeMeasurement(m) ? (
|
|
|
|
<span>{val}°</span>
|
|
|
|
) : (
|
|
|
|
<span dangerouslySetInnerHTML={{ __html: formatMm(val, imperial) }}></span>
|
|
|
|
)
|
2023-04-23 18:00:52 +02:00
|
|
|
|
2023-08-26 18:23:22 +02:00
|
|
|
export const MsetCard = ({
|
2023-08-26 16:13:11 +02:00
|
|
|
set,
|
|
|
|
onClick = false,
|
|
|
|
href = false,
|
|
|
|
useA = false,
|
|
|
|
design = false,
|
|
|
|
language = false,
|
2023-08-29 09:25:38 +02:00
|
|
|
size = 'lg',
|
2023-08-26 16:13:11 +02:00
|
|
|
}) => {
|
2023-08-29 09:25:38 +02:00
|
|
|
const sizes = {
|
|
|
|
lg: 96,
|
|
|
|
md: 52,
|
|
|
|
sm: 36,
|
|
|
|
}
|
|
|
|
const s = sizes[size]
|
2024-02-13 16:14:13 -08:00
|
|
|
const { t } = useTranslation(ns)
|
2023-08-29 09:25:38 +02:00
|
|
|
|
2023-08-26 16:13:11 +02:00
|
|
|
const wrapperProps = {
|
2023-08-29 09:25:38 +02:00
|
|
|
className: `bg-base-300 aspect-square h-${s} w-${s} mb-2
|
|
|
|
mx-auto flex flex-col items-start text-center justify-between rounded-none md:rounded shadow`,
|
2023-08-26 16:13:11 +02:00
|
|
|
style: {
|
2023-08-29 09:25:38 +02:00
|
|
|
backgroundImage: `url(${cloudflareImageUrl({ type: 'w500', id: set.img })})`,
|
2023-08-26 16:13:11 +02:00
|
|
|
backgroundSize: 'cover',
|
|
|
|
backgroundRepeat: 'no-repeat',
|
|
|
|
backgroundPosition: '50%',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if (!set.img || set.img === 'default-avatar')
|
|
|
|
wrapperProps.style.backgroundPosition = 'bottom right'
|
|
|
|
|
2023-08-29 09:25:38 +02:00
|
|
|
let icon = <span></span>
|
2024-02-12 17:11:45 -08:00
|
|
|
let missingMeasies = ''
|
|
|
|
let linebreak = ''
|
|
|
|
const maxLength = 75
|
2023-08-26 16:13:11 +02:00
|
|
|
if (design) {
|
2024-02-12 17:11:45 -08:00
|
|
|
const [hasMeasies, missing] = hasRequiredMeasurements(
|
|
|
|
designMeasurements[design],
|
|
|
|
set.measies,
|
|
|
|
true
|
|
|
|
)
|
2023-08-29 09:25:38 +02:00
|
|
|
const iconClasses = 'w-8 h-8 p-1 rounded-full -mt-2 -ml-2 shadow'
|
|
|
|
icon = hasMeasies ? (
|
|
|
|
<OkIcon className={`${iconClasses} bg-success text-success-content`} stroke={4} />
|
2023-08-26 18:23:22 +02:00
|
|
|
) : (
|
2023-08-29 09:25:38 +02:00
|
|
|
<NoIcon className={`${iconClasses} bg-error text-error-content`} stroke={3} />
|
2023-08-26 18:23:22 +02:00
|
|
|
)
|
2024-02-12 17:11:45 -08:00
|
|
|
if (missing.length > 0) {
|
2024-02-13 16:14:13 -08:00
|
|
|
const translated = missing.map((m) => {
|
|
|
|
return t(m)
|
|
|
|
})
|
|
|
|
let missingString = t('missing') + ': ' + translated.join(', ')
|
2024-02-12 17:11:45 -08:00
|
|
|
if (missingString.length > maxLength) {
|
2024-02-13 16:14:13 -08:00
|
|
|
const lastSpace = missingString.lastIndexOf(', ', maxLength)
|
|
|
|
missingString = missingString.substring(0, lastSpace) + ', ' + t('andMore') + '...'
|
2024-02-12 17:11:45 -08:00
|
|
|
}
|
|
|
|
const measieClasses = 'font-normal text-xs'
|
|
|
|
missingMeasies = <span className={`${measieClasses}`}>{missingString}</span>
|
|
|
|
linebreak = <br />
|
|
|
|
}
|
2023-08-26 16:13:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const inner = (
|
|
|
|
<>
|
2023-08-29 09:25:38 +02:00
|
|
|
{icon}
|
|
|
|
<span className="bg-neutral text-neutral-content px-4 w-full bg-opacity-50 py-2 rounded rounded-t-none font-bold leading-5">
|
2023-08-26 18:23:22 +02:00
|
|
|
{language ? set[`name${capitalize(language)}`] : set.name}
|
2024-02-12 17:11:45 -08:00
|
|
|
{linebreak}
|
|
|
|
{missingMeasies}
|
2023-08-29 09:25:38 +02:00
|
|
|
</span>
|
2023-08-23 17:41:34 +02:00
|
|
|
</>
|
|
|
|
)
|
2023-08-26 16:13:11 +02:00
|
|
|
|
|
|
|
// Is it a button with an onClick handler?
|
|
|
|
if (onClick)
|
|
|
|
return (
|
|
|
|
<button {...wrapperProps} onClick={() => onClick(set)}>
|
|
|
|
{inner}
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
|
|
|
|
// Returns a link to an internal page
|
|
|
|
if (href && !useA)
|
|
|
|
return (
|
|
|
|
<Link {...wrapperProps} href={href}>
|
|
|
|
{inner}
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
|
|
|
|
// Returns a link to an external page
|
|
|
|
if (href && useA)
|
|
|
|
return (
|
|
|
|
<a {...wrapperProps} href={href}>
|
|
|
|
{inner}
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
|
|
|
|
// Returns a div
|
|
|
|
return <div {...wrapperProps}>{inner}</div>
|
2023-08-23 17:41:34 +02:00
|
|
|
}
|
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
export const Mset = ({ id, publicOnly = false }) => {
|
|
|
|
// Hooks
|
2023-08-23 17:41:34 +02:00
|
|
|
const { account, control } = useAccount()
|
2023-09-04 08:40:05 +02:00
|
|
|
const { setLoadingStatus } = useContext(LoadingStatusContext)
|
2023-08-23 12:18:20 +02:00
|
|
|
const backend = useBackend()
|
2023-08-24 19:01:48 +02:00
|
|
|
const { t, i18n } = useTranslation(ns)
|
2023-04-23 18:00:52 +02:00
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
// Context
|
|
|
|
const { setModal } = useContext(ModalContext)
|
|
|
|
|
|
|
|
const [filter, setFilter] = useState(false)
|
|
|
|
const [edit, setEdit] = useState(false)
|
2023-09-03 17:53:19 +02:00
|
|
|
const [suggest, setSuggest] = useState(false)
|
2023-08-23 12:18:20 +02:00
|
|
|
const [mset, setMset] = useState()
|
|
|
|
// Set fields for editing
|
|
|
|
const [name, setName] = useState(mset?.name)
|
|
|
|
const [image, setImage] = useState(mset?.image)
|
|
|
|
const [isPublic, setIsPublic] = useState(mset?.public ? true : false)
|
|
|
|
const [imperial, setImperial] = useState(mset?.imperial ? true : false)
|
|
|
|
const [notes, setNotes] = useState(mset?.notes || '')
|
|
|
|
const [measies, setMeasies] = useState({})
|
|
|
|
|
|
|
|
// Effect
|
|
|
|
useEffect(() => {
|
|
|
|
const getSet = async () => {
|
|
|
|
setLoadingStatus([true, t('backendLoadingStarted')])
|
|
|
|
const result = await backend.getSet(id)
|
|
|
|
if (result.success) {
|
|
|
|
setMset(result.data.set)
|
|
|
|
setName(result.data.set.name)
|
|
|
|
setImage(result.data.set.image)
|
|
|
|
setIsPublic(result.data.set.public ? true : false)
|
|
|
|
setImperial(result.data.set.imperial ? true : false)
|
|
|
|
setNotes(result.data.set.notes)
|
|
|
|
setMeasies(result.data.set.measies)
|
|
|
|
setLoadingStatus([true, 'backendLoadingCompleted', true, true])
|
|
|
|
} else setLoadingStatus([true, 'backendError', true, false])
|
2023-04-30 17:50:15 +02:00
|
|
|
}
|
2023-08-23 12:18:20 +02:00
|
|
|
const getPublicSet = async () => {
|
|
|
|
setLoadingStatus([true, t('backendLoadingStarted')])
|
|
|
|
const result = await backend.getPublicSet(id)
|
|
|
|
if (result.success) {
|
|
|
|
setMset({
|
|
|
|
...result.data,
|
|
|
|
public: true,
|
|
|
|
measies: result.data.measurements,
|
|
|
|
})
|
|
|
|
setName(result.data.name)
|
|
|
|
setImage(result.data.image)
|
|
|
|
setIsPublic(result.data.public ? true : false)
|
|
|
|
setImperial(result.data.imperial ? true : false)
|
|
|
|
setNotes(result.data.notes)
|
|
|
|
setMeasies(result.data.measurements)
|
|
|
|
setLoadingStatus([true, 'backendLoadingCompleted', true, true])
|
|
|
|
} else setLoadingStatus([true, 'backendError', true, false])
|
2023-04-23 18:00:52 +02:00
|
|
|
}
|
2023-08-23 12:18:20 +02:00
|
|
|
if (id) {
|
|
|
|
if (publicOnly) getPublicSet()
|
|
|
|
else getSet()
|
2023-04-23 18:00:52 +02:00
|
|
|
}
|
2023-08-23 12:18:20 +02:00
|
|
|
}, [id, publicOnly])
|
2023-04-23 18:00:52 +02:00
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
const filterMeasurements = () => {
|
|
|
|
if (!filter) return measurements.map((m) => t(`measurements:${m}`) + `|${m}`).sort()
|
|
|
|
else return designMeasurements[filter].map((m) => t(`measurements:${m}`) + `|${m}`).sort()
|
2023-04-23 18:00:52 +02:00
|
|
|
}
|
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
if (!id || !mset) return null
|
2023-04-23 18:00:52 +02:00
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
const updateMeasies = (m, val) => {
|
|
|
|
const newMeasies = { ...measies }
|
|
|
|
newMeasies[m] = val
|
|
|
|
setMeasies(newMeasies)
|
2023-04-23 18:00:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const save = async () => {
|
2023-08-23 12:18:20 +02:00
|
|
|
setLoadingStatus([true, 'gatheringInfo'])
|
|
|
|
// Compile data
|
|
|
|
const data = { measies: {} }
|
|
|
|
if (name || name !== mset.name) data.name = name
|
|
|
|
if (image || image !== mset.image) data.img = image
|
|
|
|
if ([true, false].includes(isPublic) && isPublic !== mset.public) data.public = isPublic
|
|
|
|
if ([true, false].includes(imperial) && imperial !== mset.imperial) data.imperial = imperial
|
|
|
|
if (notes || notes !== mset.notes) data.notes = notes
|
|
|
|
// Add measurements
|
|
|
|
for (const m of measurements) {
|
|
|
|
if (measies[m] || measies[m] !== mset.measies[m]) data.measies[m] = measies[m]
|
2023-04-23 18:00:52 +02:00
|
|
|
}
|
2023-08-23 12:18:20 +02:00
|
|
|
setLoadingStatus([true, 'savingSet'])
|
|
|
|
const result = await backend.updateSet(mset.id, data)
|
|
|
|
if (result.success) {
|
|
|
|
setMset(result.data.set)
|
|
|
|
setEdit(false)
|
|
|
|
setLoadingStatus([true, 'nailedIt', true, true])
|
|
|
|
} else setLoadingStatus([true, 'backendError', true, false])
|
2023-04-23 18:00:52 +02:00
|
|
|
}
|
2023-08-29 17:08:16 +02:00
|
|
|
|
2024-03-17 11:18:21 +01:00
|
|
|
const importSet = async () => {
|
|
|
|
setLoadingStatus([true, t('account.importing')])
|
|
|
|
// Compile data
|
|
|
|
const data = {
|
|
|
|
...mset,
|
|
|
|
userId: account.id,
|
|
|
|
measies: { ...mset.measies },
|
|
|
|
}
|
|
|
|
delete data.img
|
|
|
|
const result = await backend.createSet(data)
|
|
|
|
if (result.success) {
|
|
|
|
setMset(result.data.set)
|
|
|
|
setEdit(false)
|
|
|
|
setLoadingStatus([true, 'nailedIt', true, true])
|
|
|
|
} else setLoadingStatus([true, 'backendError', true, false])
|
|
|
|
}
|
|
|
|
|
2023-10-09 11:42:16 +02:00
|
|
|
const docs = {}
|
|
|
|
for (const option of ['name', 'units', 'public', 'notes', 'image']) {
|
2023-10-25 20:15:24 +02:00
|
|
|
docs[option] = <DynamicMdx language={i18n.language} slug={`docs/about/site/sets/${option}`} />
|
2023-10-09 11:42:16 +02:00
|
|
|
}
|
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
const heading = (
|
2023-08-26 18:23:22 +02:00
|
|
|
<>
|
|
|
|
<div className="flex flex-wrap md:flex-nowrap flex-row gap-2 w-full">
|
|
|
|
<div className="w-full md:w-96 shrink-0">
|
|
|
|
<MsetCard set={mset} control={control} />
|
2023-04-30 17:50:15 +02:00
|
|
|
</div>
|
2023-08-26 18:23:22 +02:00
|
|
|
<div className="flex flex-col justify-end gap-2 mb-2 grow">
|
|
|
|
{account.control > 3 && mset.public ? (
|
|
|
|
<div className="flex flex-row gap-2 items-center">
|
|
|
|
<a
|
|
|
|
className="badge badge-secondary font-bold badge-lg"
|
|
|
|
href={`${conf.backend}/sets/${mset.id}.json`}
|
2023-08-23 12:18:20 +02:00
|
|
|
>
|
2023-08-26 18:23:22 +02:00
|
|
|
JSON
|
|
|
|
</a>
|
|
|
|
<a
|
|
|
|
className="badge badge-success font-bold badge-lg"
|
|
|
|
href={`${conf.backend}/sets/${mset.id}.yaml`}
|
|
|
|
>
|
|
|
|
YAML
|
|
|
|
</a>
|
2023-08-23 12:18:20 +02:00
|
|
|
</div>
|
|
|
|
) : (
|
2023-08-26 18:23:22 +02:00
|
|
|
<span></span>
|
2023-08-23 12:18:20 +02:00
|
|
|
)}
|
2024-03-17 11:18:21 +01:00
|
|
|
{account.control > 2 && mset.public && mset.userId !== account.id ? (
|
|
|
|
<button className="btn btn-primary" title={t('account:importSet')} onClick={importSet}>
|
|
|
|
<div className="flex flex-row gap-4 justify-between items-center w-full">
|
|
|
|
<UploadIcon />
|
|
|
|
{t('account:importSet')}
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
) : null}
|
2024-03-13 16:30:40 +01:00
|
|
|
{account.control > 2 ? (
|
2023-09-26 12:44:12 +02:00
|
|
|
<BookmarkButton slug={`sets/${mset.id}`} title={mset.name} type="set" thing="set" />
|
2023-09-24 12:39:25 +02:00
|
|
|
) : null}
|
2023-08-26 18:23:22 +02:00
|
|
|
<button
|
|
|
|
onClick={() =>
|
|
|
|
setModal(
|
|
|
|
<ModalWrapper flex="col" justify="top lg:justify-center" slideFrom="right">
|
|
|
|
<img src={cloudflareImageUrl({ type: 'public', id: mset.img })} />
|
|
|
|
</ModalWrapper>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
className={`btn btn-secondary btn-outline ${horFlexClasses}`}
|
|
|
|
>
|
|
|
|
<CameraIcon />
|
|
|
|
{t('showImage')}
|
|
|
|
</button>
|
|
|
|
{!publicOnly && (
|
|
|
|
<>
|
2023-10-04 19:24:41 +02:00
|
|
|
{account.control > 2 ? (
|
2023-09-03 17:53:19 +02:00
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
setSuggest(!suggest)
|
|
|
|
setEdit(false)
|
|
|
|
}}
|
|
|
|
className={`btn ${
|
|
|
|
suggest ? 'btn-neutral' : 'btn-primary'
|
|
|
|
} btn-outline ${horFlexClasses}`}
|
|
|
|
>
|
|
|
|
{suggest ? <ResetIcon /> : <CsetIcon />}
|
|
|
|
{t(suggest ? 'account:cancel' : 'account:suggestForCuration')}
|
|
|
|
</button>
|
|
|
|
) : null}
|
2023-08-26 18:23:22 +02:00
|
|
|
{edit ? (
|
|
|
|
<>
|
|
|
|
<button
|
2023-09-03 17:53:19 +02:00
|
|
|
onClick={() => {
|
|
|
|
setEdit(false)
|
|
|
|
setSuggest(false)
|
|
|
|
}}
|
2023-08-26 18:23:22 +02:00
|
|
|
className={`btn btn-neutral btn-outline ${horFlexClasses}`}
|
|
|
|
>
|
|
|
|
<ResetIcon />
|
|
|
|
{t('cancel')}
|
|
|
|
</button>
|
|
|
|
<button onClick={save} className={`btn btn-primary ${horFlexClasses}`}>
|
|
|
|
<UploadIcon />
|
|
|
|
{t('saveThing', { thing: t('account:set') })}
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<button
|
2023-09-03 17:53:19 +02:00
|
|
|
onClick={() => {
|
|
|
|
setEdit(true)
|
|
|
|
setSuggest(false)
|
|
|
|
}}
|
2023-08-26 18:23:22 +02:00
|
|
|
className={`btn btn-primary ${horFlexClasses}`}
|
|
|
|
>
|
|
|
|
<EditIcon /> {t('editThing', { thing: t('account:set') })}
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
2024-03-17 11:18:21 +01:00
|
|
|
{account.control > 2 && mset.userId === account.id ? (
|
|
|
|
<button className="btn btn-neutral" title={t('account:cloneSet')} onClick={importSet}>
|
|
|
|
<div className="flex flex-row gap-4 justify-between items-center w-full">
|
|
|
|
<CloneIcon />
|
|
|
|
{t('account:cloneSet')}
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
) : null}
|
2023-08-26 18:23:22 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-row flex-wrap gap-4 text-sm items-center justify-between mb-2"></div>
|
|
|
|
</>
|
2023-08-23 12:18:20 +02:00
|
|
|
)
|
2023-04-30 18:29:56 +02:00
|
|
|
|
2023-09-03 17:53:19 +02:00
|
|
|
if (suggest)
|
|
|
|
return (
|
|
|
|
<div className="max-w-2xl">
|
|
|
|
{heading}
|
|
|
|
<SuggestCset {...{ mset, setLoadingStatus, backend, t }} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
if (!edit)
|
|
|
|
return (
|
|
|
|
<div className="max-w-2xl">
|
|
|
|
{heading}
|
|
|
|
{Object.keys(mset.measies).length > 0 && (
|
|
|
|
<>
|
|
|
|
<h2>{t('measies')}</h2>
|
2023-08-25 16:14:48 +02:00
|
|
|
{Object.entries(mset.measies).map(([m, val]) =>
|
|
|
|
val > 0 ? (
|
2023-09-12 13:52:07 +02:00
|
|
|
<DisplayRow title={<MeasieVal {...{ m, val, imperial: mset.imperial }} />} key={m}>
|
2023-08-25 16:14:48 +02:00
|
|
|
<span className="font-medium">{t(m)}</span>
|
|
|
|
</DisplayRow>
|
|
|
|
) : null
|
|
|
|
)}
|
2023-08-23 12:18:20 +02:00
|
|
|
</>
|
|
|
|
)}
|
2023-04-30 18:29:56 +02:00
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
<h2>{t('data')}</h2>
|
2023-08-23 17:47:21 +02:00
|
|
|
<DisplayRow title={t('name')}>{mset.name}</DisplayRow>
|
|
|
|
<DisplayRow title={t('units')}>
|
2024-02-22 09:18:33 -08:00
|
|
|
{mset.imperial ? t('imperialUnits') : t('metricUnits')}
|
2023-08-23 17:47:21 +02:00
|
|
|
</DisplayRow>
|
2023-08-23 17:41:34 +02:00
|
|
|
{control >= controlLevels.sets.notes && (
|
2023-08-23 17:47:21 +02:00
|
|
|
<DisplayRow title={t('notes')}>
|
2023-10-10 09:05:22 +02:00
|
|
|
<Mdx md={mset.notes} />
|
2023-08-23 17:47:21 +02:00
|
|
|
</DisplayRow>
|
2023-08-23 12:18:20 +02:00
|
|
|
)}
|
2023-08-23 17:41:34 +02:00
|
|
|
{control >= controlLevels.sets.public && (
|
|
|
|
<>
|
2023-08-23 17:47:21 +02:00
|
|
|
<DisplayRow title={t('public')}>
|
2023-08-23 17:41:34 +02:00
|
|
|
{mset.public ? (
|
|
|
|
<OkIcon className="w-6 h-6 text-success" stroke={4} />
|
|
|
|
) : (
|
|
|
|
<NoIcon className="w-6 h-6 text-error" stroke={3} />
|
|
|
|
)}
|
2023-08-23 17:47:21 +02:00
|
|
|
</DisplayRow>
|
2023-08-23 17:41:34 +02:00
|
|
|
{mset.public && (
|
2023-08-23 17:47:21 +02:00
|
|
|
<DisplayRow title={t('permalink')}>
|
2023-10-22 13:19:30 +02:00
|
|
|
<PageLink href={`/set?id=${mset.id}`} txt={`/set?id=${mset.id}`} />
|
2023-08-23 17:47:21 +02:00
|
|
|
</DisplayRow>
|
2023-08-23 17:41:34 +02:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{control >= controlLevels.sets.createdAt && (
|
2023-08-23 17:47:21 +02:00
|
|
|
<DisplayRow title={t('created')}>
|
2023-08-23 17:41:34 +02:00
|
|
|
<Timeago date={mset.createdAt} />
|
|
|
|
<span className="px-2 opacity-50">|</span>
|
2023-08-24 19:01:48 +02:00
|
|
|
{shortDate(i18n.language, mset.createdAt, false)}
|
2023-08-23 17:47:21 +02:00
|
|
|
</DisplayRow>
|
2023-08-23 17:41:34 +02:00
|
|
|
)}
|
2023-08-29 17:08:16 +02:00
|
|
|
{control >= controlLevels.sets.updatedAt && (
|
2023-08-23 17:47:21 +02:00
|
|
|
<DisplayRow title={t('updated')}>
|
2023-08-23 17:41:34 +02:00
|
|
|
<Timeago date={mset.updatedAt} />
|
|
|
|
<span className="px-2 opacity-50">|</span>
|
2023-08-29 17:08:16 +02:00
|
|
|
{shortDate(i18n.language, mset.updatedAt, false)}
|
2023-08-23 17:47:21 +02:00
|
|
|
</DisplayRow>
|
2023-08-23 17:41:34 +02:00
|
|
|
)}
|
2023-08-23 17:47:21 +02:00
|
|
|
{control >= controlLevels.sets.id && <DisplayRow title={t('id')}>{mset.id}</DisplayRow>}
|
2023-08-23 12:18:20 +02:00
|
|
|
</div>
|
|
|
|
)
|
2023-04-30 17:50:15 +02:00
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
return (
|
|
|
|
<div className="max-w-2xl">
|
|
|
|
{heading}
|
|
|
|
<ul className="list list-disc list-inside ml-4">
|
|
|
|
{['measies', 'data'].map((s) => (
|
|
|
|
<li key={s}>
|
|
|
|
<AnchorLink id={s} txt={t(s)} />
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
<ul className="list list-disc list-inside ml-4">
|
2023-08-23 17:41:34 +02:00
|
|
|
<li>
|
|
|
|
<AnchorLink id="name" txt={t('name')} />
|
|
|
|
</li>
|
|
|
|
{account.control >= conf.account.sets.img ? (
|
2023-08-23 12:18:20 +02:00
|
|
|
<li>
|
2023-08-23 17:41:34 +02:00
|
|
|
<AnchorLink id="image" txt={t('image')} />
|
2023-08-23 12:18:20 +02:00
|
|
|
</li>
|
2023-08-23 17:41:34 +02:00
|
|
|
) : null}
|
|
|
|
{['public', 'units', 'notes'].map((id) =>
|
|
|
|
account.control >= conf.account.sets[id] ? (
|
2023-08-24 18:39:12 +02:00
|
|
|
<li key={id}>
|
2023-08-23 17:41:34 +02:00
|
|
|
<AnchorLink id="units" txt={t(id)} />
|
|
|
|
</li>
|
|
|
|
) : null
|
|
|
|
)}
|
2023-08-23 12:18:20 +02:00
|
|
|
</ul>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<h2 id="measies">{t('measies')}</h2>
|
2023-08-23 17:41:34 +02:00
|
|
|
<div className="bg-secondary px-4 pt-1 pb-4 rounded-lg shadow bg-opacity-10">
|
|
|
|
<DesignDropdown
|
|
|
|
update={setFilter}
|
|
|
|
label={t('filterByDesign')}
|
|
|
|
current={filter}
|
|
|
|
firstOption={<option value="">{t('noFilter')}</option>}
|
|
|
|
/>
|
2023-04-23 18:00:52 +02:00
|
|
|
</div>
|
2023-08-23 12:18:20 +02:00
|
|
|
{filterMeasurements().map((mplus) => {
|
|
|
|
const [translated, m] = mplus.split('|')
|
|
|
|
|
|
|
|
return (
|
|
|
|
<MeasieInput
|
2023-08-26 09:27:27 +02:00
|
|
|
id={`measie-${m}`}
|
2023-08-23 12:18:20 +02:00
|
|
|
key={m}
|
|
|
|
m={m}
|
|
|
|
imperial={mset.imperial}
|
|
|
|
label={translated}
|
|
|
|
current={mset.measies[m]}
|
|
|
|
original={mset.measies[m]}
|
|
|
|
update={updateMeasies}
|
2023-10-09 11:42:16 +02:00
|
|
|
docs={
|
|
|
|
<DynamicMdx language={i18n.language} slug={`docs/measurements/${m.toLowerCase()}`} />
|
|
|
|
}
|
2023-08-23 12:18:20 +02:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
})}
|
2023-04-23 18:00:52 +02:00
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
<h2 id="data">{t('data')}</h2>
|
2023-04-28 21:23:06 +02:00
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
{/* Name is always shown */}
|
|
|
|
<span id="name"></span>
|
|
|
|
<StringInput
|
2023-08-26 09:27:27 +02:00
|
|
|
id="set-name"
|
2023-08-23 12:18:20 +02:00
|
|
|
label={t('name')}
|
|
|
|
update={setName}
|
|
|
|
current={name}
|
|
|
|
original={mset.name}
|
|
|
|
placeholder="Georg Cantor"
|
|
|
|
valid={(val) => val && val.length > 0}
|
2023-10-09 11:42:16 +02:00
|
|
|
docs={docs.name}
|
2023-08-23 12:18:20 +02:00
|
|
|
/>
|
2023-04-22 16:41:13 +02:00
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
{/* img: Control level determines whether or not to show this */}
|
|
|
|
<span id="image"></span>
|
|
|
|
{account.control >= conf.account.sets.img ? (
|
|
|
|
<PassiveImageInput
|
2023-08-26 09:27:27 +02:00
|
|
|
id="set-img"
|
2023-08-23 12:18:20 +02:00
|
|
|
label={t('image')}
|
|
|
|
update={setImage}
|
|
|
|
current={image}
|
|
|
|
valid={(val) => val.length > 0}
|
2023-10-09 11:42:16 +02:00
|
|
|
docs={docs.image}
|
2023-08-23 12:18:20 +02:00
|
|
|
/>
|
|
|
|
) : null}
|
2023-04-22 16:41:13 +02:00
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
{/* public: Control level determines whether or not to show this */}
|
|
|
|
<span id="public"></span>
|
|
|
|
{account.control >= conf.account.sets.public ? (
|
|
|
|
<ListInput
|
2023-08-26 09:27:27 +02:00
|
|
|
id="set-public"
|
2023-08-23 12:18:20 +02:00
|
|
|
label={t('public')}
|
|
|
|
update={setIsPublic}
|
|
|
|
list={[
|
|
|
|
{
|
|
|
|
val: true,
|
|
|
|
label: (
|
|
|
|
<div className="flex flex-row items-center flex-wrap justify-between w-full">
|
|
|
|
<span>{t('publicSet')}</span>
|
|
|
|
<OkIcon
|
|
|
|
className="w-8 h-8 text-success bg-base-100 rounded-full p-1"
|
|
|
|
stroke={4}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
desc: t('publicSetDesc'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
val: false,
|
|
|
|
label: (
|
|
|
|
<div className="flex flex-row items-center flex-wrap justify-between w-full">
|
|
|
|
<span>{t('privateSet')}</span>
|
|
|
|
<NoIcon className="w-8 h-8 text-error bg-base-100 rounded-full p-1" stroke={3} />
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
desc: t('privateSetDesc'),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
current={isPublic}
|
2023-10-09 11:42:16 +02:00
|
|
|
docs={docs.public}
|
2023-08-23 12:18:20 +02:00
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
{/* units: Control level determines whether or not to show this */}
|
|
|
|
<span id="units"></span>
|
|
|
|
{account.control >= conf.account.sets.units ? (
|
2024-02-22 09:14:59 -08:00
|
|
|
<>
|
|
|
|
<ListInput
|
|
|
|
id="set-units"
|
|
|
|
label={t('units')}
|
|
|
|
update={setImperial}
|
|
|
|
list={[
|
|
|
|
{
|
|
|
|
val: false,
|
|
|
|
label: (
|
|
|
|
<div className="flex flex-row items-center flex-wrap justify-between w-full">
|
|
|
|
<span>{t('metricUnits')}</span>
|
|
|
|
<span className="text-inherit text-2xl pr-2">cm</span>
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
desc: t('metricUnitsd'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
val: true,
|
|
|
|
label: (
|
|
|
|
<div className="flex flex-row items-center flex-wrap justify-between w-full">
|
|
|
|
<span>{t('imperialUnits')}</span>
|
|
|
|
<span className="text-inherit text-4xl pr-2">″</span>
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
desc: t('imperialUnitsd'),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
current={imperial}
|
|
|
|
docs={docs.units}
|
|
|
|
/>
|
|
|
|
<span className="text-large text-warning">{t('unitsMustSave')}</span>
|
|
|
|
</>
|
2023-08-23 12:18:20 +02:00
|
|
|
) : null}
|
|
|
|
|
|
|
|
{/* notes: Control level determines whether or not to show this */}
|
|
|
|
<span id="notes"></span>
|
|
|
|
{account.control >= conf.account.sets.notes ? (
|
|
|
|
<MarkdownInput
|
2023-08-26 09:27:27 +02:00
|
|
|
id="set-notes"
|
2023-08-23 12:18:20 +02:00
|
|
|
label={t('notes')}
|
|
|
|
update={setNotes}
|
|
|
|
current={notes}
|
|
|
|
placeholder={t('mdSupport')}
|
2023-10-09 11:42:16 +02:00
|
|
|
docs={docs.notes}
|
2023-08-23 12:18:20 +02:00
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<button
|
|
|
|
onClick={save}
|
|
|
|
className="btn btn-primary btn-lg flex flex-row items-center gap-4 mx-auto mt-8"
|
|
|
|
>
|
|
|
|
<UploadIcon />
|
|
|
|
{t('saveThing', { thing: t('account:set') })}
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-04-22 16:41:13 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Component for the account/sets page
|
2023-08-25 10:44:05 +02:00
|
|
|
export const Sets = () => {
|
2023-04-28 21:23:06 +02:00
|
|
|
// Hooks
|
2023-08-23 17:41:34 +02:00
|
|
|
const { control } = useAccount()
|
2023-08-20 18:48:40 +02:00
|
|
|
const backend = useBackend()
|
2023-08-24 19:01:48 +02:00
|
|
|
const { t } = useTranslation(ns)
|
2023-09-04 08:40:05 +02:00
|
|
|
const { setLoadingStatus, LoadingProgress } = useContext(LoadingStatusContext)
|
2023-04-22 16:41:13 +02:00
|
|
|
|
2023-04-28 21:23:06 +02:00
|
|
|
// State
|
2023-04-22 16:41:13 +02:00
|
|
|
const [sets, setSets] = useState([])
|
2023-08-23 12:18:20 +02:00
|
|
|
const [selected, setSelected] = useState({})
|
|
|
|
const [refresh, setRefresh] = useState(0)
|
2023-04-22 16:41:13 +02:00
|
|
|
|
2023-04-28 21:23:06 +02:00
|
|
|
// Effects
|
2023-04-22 16:41:13 +02:00
|
|
|
useEffect(() => {
|
|
|
|
const getSets = async () => {
|
|
|
|
const result = await backend.getSets()
|
|
|
|
if (result.success) setSets(result.data.sets)
|
|
|
|
}
|
|
|
|
getSets()
|
2023-08-23 12:18:20 +02:00
|
|
|
}, [refresh])
|
|
|
|
|
|
|
|
// Helper var to see how many are selected
|
|
|
|
const selCount = Object.keys(selected).length
|
2023-04-22 16:41:13 +02:00
|
|
|
|
2023-08-23 12:18:20 +02:00
|
|
|
// Helper method to toggle single selection
|
|
|
|
const toggleSelect = (id) => {
|
|
|
|
const newSelected = { ...selected }
|
|
|
|
if (newSelected[id]) delete newSelected[id]
|
|
|
|
else newSelected[id] = 1
|
|
|
|
setSelected(newSelected)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper method to toggle select all
|
|
|
|
const toggleSelectAll = () => {
|
|
|
|
if (selCount === sets.length) setSelected({})
|
|
|
|
else {
|
|
|
|
const newSelected = {}
|
|
|
|
for (const set of sets) newSelected[set.id] = 1
|
|
|
|
setSelected(newSelected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper to delete one or more measurements sets
|
|
|
|
const removeSelectedSets = async () => {
|
|
|
|
let i = 0
|
|
|
|
for (const id in selected) {
|
|
|
|
i++
|
|
|
|
await backend.removeSet(id)
|
2023-08-25 10:44:05 +02:00
|
|
|
setLoadingStatus([
|
|
|
|
true,
|
|
|
|
<LoadingProgress val={i} max={selCount} msg={t('removingSets')} key="linter" />,
|
|
|
|
])
|
2023-08-23 12:18:20 +02:00
|
|
|
}
|
|
|
|
setSelected({})
|
|
|
|
setRefresh(refresh + 1)
|
|
|
|
setLoadingStatus([true, 'nailedIt', true, true])
|
2023-04-30 17:50:15 +02:00
|
|
|
}
|
2023-04-22 16:41:13 +02:00
|
|
|
|
|
|
|
return (
|
2023-08-26 18:23:22 +02:00
|
|
|
<div className="max-w-7xl xl:pl-4">
|
2023-09-24 12:28:08 +02:00
|
|
|
{sets.length > 0 ? (
|
|
|
|
<>
|
|
|
|
<p className="text-center md:text-right">
|
2024-03-17 11:18:21 +01:00
|
|
|
<Link
|
|
|
|
className="btn btn-primary btn-outline capitalize w-full md:w-auto mr-2"
|
|
|
|
bottom
|
|
|
|
primary
|
|
|
|
href="/account/import"
|
|
|
|
>
|
|
|
|
<UploadIcon />
|
|
|
|
{t('account:importSets')}
|
|
|
|
</Link>
|
2023-09-24 12:28:08 +02:00
|
|
|
<Link
|
|
|
|
className="btn btn-primary capitalize w-full md:w-auto"
|
|
|
|
bottom
|
|
|
|
primary
|
|
|
|
href="/new/set"
|
|
|
|
>
|
|
|
|
<PlusIcon />
|
|
|
|
{t('newSet')}
|
|
|
|
</Link>
|
|
|
|
</p>
|
|
|
|
<div className="flex flex-row gap-2 border-b-2 mb-4 pb-4 mt-8 h-14 items-center">
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
className="checkbox checkbox-secondary"
|
|
|
|
onClick={toggleSelectAll}
|
|
|
|
checked={sets.length === selCount}
|
|
|
|
/>
|
2024-01-02 15:50:47 +02:00
|
|
|
<button className="btn btn-error" onClick={removeSelectedSets} disabled={selCount < 1}>
|
|
|
|
<TrashIcon /> {selCount} {t('sets')}
|
|
|
|
</button>
|
2023-09-24 12:28:08 +02:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) : (
|
2023-08-23 17:41:34 +02:00
|
|
|
<Link
|
2023-09-24 12:28:08 +02:00
|
|
|
className="btn btn-primary capitalize w-full md:w-auto btn-lg"
|
2023-08-23 17:41:34 +02:00
|
|
|
bottom
|
|
|
|
primary
|
|
|
|
href="/new/set"
|
|
|
|
>
|
2023-08-23 18:49:21 +02:00
|
|
|
<PlusIcon />
|
2023-08-23 12:18:20 +02:00
|
|
|
{t('newSet')}
|
|
|
|
</Link>
|
2023-09-24 12:28:08 +02:00
|
|
|
)}
|
2023-08-29 14:11:51 +02:00
|
|
|
<div className="flex flex-row flex-wrap gap-2">
|
2023-08-26 18:23:22 +02:00
|
|
|
{sets.map((set, i) => (
|
|
|
|
<div
|
|
|
|
key={i}
|
|
|
|
className={`flex flex-row items-start gap-1 border-2
|
|
|
|
${
|
|
|
|
selected[set.id] ? 'border-solid border-secondary' : 'border-dotted border-base-300'
|
|
|
|
} rounded-lg p-2`}
|
|
|
|
>
|
|
|
|
<label className="w-8 h-full shrink-0">
|
2023-08-23 12:18:20 +02:00
|
|
|
<input
|
|
|
|
type="checkbox"
|
2023-08-26 18:23:22 +02:00
|
|
|
checked={selected[set.id] ? true : false}
|
2023-08-23 12:18:20 +02:00
|
|
|
className="checkbox checkbox-secondary"
|
2023-08-26 18:23:22 +02:00
|
|
|
onClick={() => toggleSelect(set.id)}
|
2023-08-23 12:18:20 +02:00
|
|
|
/>
|
2023-08-26 18:23:22 +02:00
|
|
|
</label>
|
|
|
|
<div className="w-full">
|
2023-10-22 13:19:30 +02:00
|
|
|
<MsetCard control={control} href={`/account/set?id=${set.id}`} set={set} size="md" />
|
2023-08-26 18:23:22 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
2023-05-26 10:41:36 +02:00
|
|
|
<BackToAccountButton />
|
2023-04-22 16:41:13 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2023-08-26 16:13:11 +02:00
|
|
|
|
|
|
|
export const SetCard = ({
|
|
|
|
set,
|
|
|
|
requiredMeasies = [],
|
|
|
|
href = false,
|
|
|
|
onClick = false,
|
|
|
|
useA = false,
|
|
|
|
}) => {
|
|
|
|
// Hooks
|
|
|
|
const { t } = useTranslation(['sets'])
|
|
|
|
|
2023-08-27 17:01:58 +02:00
|
|
|
const [hasMeasies] = hasRequiredMeasurements(requiredMeasies, set.measies, true)
|
2023-08-26 16:13:11 +02:00
|
|
|
|
|
|
|
const wrapperProps = {
|
|
|
|
className:
|
|
|
|
'bg-base-300 w-full mb-2 mx-auto flex flex-col items-start text-center justify-center rounded shadow py-4',
|
|
|
|
style: {
|
|
|
|
backgroundImage: `url(${cloudflareImageUrl({ type: 'w1000', id: set.img })})`,
|
|
|
|
backgroundSize: 'cover',
|
|
|
|
backgroundRepeat: 'no-repeat',
|
|
|
|
backgroundPosition: '50%',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if (set.img === 'default-avatar') wrapperProps.style.backgroundPosition = 'bottom right'
|
|
|
|
|
|
|
|
const inner = hasMeasies ? null : (
|
|
|
|
<div className="flex flex-row gap-2 items-center">
|
|
|
|
<WarningIcon className="w-6 h-6 shrink-0 text-error" />
|
2023-08-27 17:01:58 +02:00
|
|
|
<span>{t('setLacksMeasiesForDesign')}</span>
|
2023-08-26 16:13:11 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
// Is it a button with an onClick handler?
|
|
|
|
if (onClick)
|
|
|
|
return (
|
|
|
|
<button {...wrapperProps} onClick={onClick}>
|
|
|
|
{inner}
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
|
|
|
|
// Returns a link to an internal page
|
|
|
|
if (href && !useA)
|
|
|
|
return (
|
|
|
|
<Link {...wrapperProps} href={href}>
|
|
|
|
{inner}
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
|
|
|
|
// Returns a link to an external page
|
|
|
|
if (href && useA)
|
|
|
|
return (
|
|
|
|
<a {...wrapperProps} href={href}>
|
|
|
|
{inner}
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
|
|
|
|
// Returns a div
|
|
|
|
return <div {...wrapperProps}>{inner}</div>
|
|
|
|
}
|
|
|
|
|
2023-08-26 18:23:22 +02:00
|
|
|
export const MsetButton = (props) => <MsetCard {...props} href={false} />
|
|
|
|
export const MsetLink = (props) => <MsetCard {...props} onClick={false} useA={false} />
|
|
|
|
export const MsetA = (props) => <MsetCard {...props} onClick={false} useA={true} />
|
2023-08-26 16:13:11 +02:00
|
|
|
|
2024-02-12 19:46:11 -08:00
|
|
|
export const UserSetPicker = ({
|
|
|
|
design,
|
|
|
|
t,
|
|
|
|
href,
|
|
|
|
clickHandler,
|
|
|
|
missingClickHandler,
|
|
|
|
size = 'lg',
|
|
|
|
}) => {
|
2023-08-26 16:13:11 +02:00
|
|
|
// Hooks
|
|
|
|
const backend = useBackend()
|
|
|
|
const { control } = useAccount()
|
|
|
|
|
|
|
|
// State
|
|
|
|
const [sets, setSets] = useState({})
|
|
|
|
|
|
|
|
// Effects
|
|
|
|
useEffect(() => {
|
|
|
|
const getSets = async () => {
|
|
|
|
const result = await backend.getSets()
|
|
|
|
if (result.success) {
|
|
|
|
const all = {}
|
|
|
|
for (const set of result.data.sets) all[set.id] = set
|
|
|
|
setSets(all)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getSets()
|
|
|
|
}, [backend])
|
|
|
|
|
|
|
|
let hasSets = false
|
|
|
|
const okSets = []
|
|
|
|
const lackingSets = []
|
|
|
|
if (Object.keys(sets).length > 0) {
|
|
|
|
hasSets = true
|
|
|
|
for (const setId in sets) {
|
2023-08-27 17:01:58 +02:00
|
|
|
const [hasMeasies] = hasRequiredMeasurements(
|
2023-08-26 18:23:22 +02:00
|
|
|
designMeasurements[design],
|
2023-08-26 16:13:11 +02:00
|
|
|
sets[setId].measies,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
if (hasMeasies) okSets.push(sets[setId])
|
|
|
|
else lackingSets.push(sets[setId])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasSets)
|
|
|
|
return (
|
|
|
|
<div className="w-full max-w-3xl mx-auto">
|
|
|
|
<Popout tip>
|
|
|
|
<h5>{t('account:noOwnSets')}</h5>
|
|
|
|
<p className="text-lg">{t('account:pleaseMtm')}</p>
|
|
|
|
<p className="text-lg">{t('account:noOwnSetsMsg')}</p>
|
|
|
|
<p className="text-center md:text-right">
|
|
|
|
<Link
|
|
|
|
className="btn btn-primary capitalize w-full md:w-auto"
|
|
|
|
bottom
|
|
|
|
primary
|
|
|
|
href="/new/set"
|
|
|
|
>
|
|
|
|
<PlusIcon />
|
|
|
|
{t('account:newSet')}
|
|
|
|
</Link>
|
|
|
|
</p>
|
|
|
|
</Popout>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{okSets.length > 0 && (
|
2023-08-29 09:25:38 +02:00
|
|
|
<div className="flex flex-row flex-wrap gap-2">
|
|
|
|
{okSets.map((set) => (
|
|
|
|
<MsetButton
|
|
|
|
{...{ set, control, design }}
|
|
|
|
onClick={clickHandler}
|
|
|
|
href={href}
|
|
|
|
requiredMeasies={measurements[design]}
|
|
|
|
key={set.id}
|
|
|
|
size={size}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
2023-08-26 16:13:11 +02:00
|
|
|
)}
|
|
|
|
{lackingSets.length > 0 && (
|
|
|
|
<div className="my-4">
|
2023-08-29 09:25:38 +02:00
|
|
|
<Popout note compact>
|
|
|
|
{t('account:someSetsLacking')}
|
|
|
|
</Popout>
|
2023-08-26 18:23:22 +02:00
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 2xl:grid-cols-3 gap-2">
|
2023-08-27 17:01:58 +02:00
|
|
|
{lackingSets.map((set) => (
|
2024-02-12 19:46:11 -08:00
|
|
|
<MsetButton
|
2023-08-26 18:23:22 +02:00
|
|
|
{...{ set, control, design }}
|
2024-02-12 19:46:11 -08:00
|
|
|
onClick={missingClickHandler}
|
|
|
|
href={href}
|
2023-08-26 18:23:22 +02:00
|
|
|
requiredMeasies={measurements[design]}
|
|
|
|
key={set.id}
|
2023-08-29 09:25:38 +02:00
|
|
|
size={size}
|
2023-08-26 18:23:22 +02:00
|
|
|
/>
|
2023-08-26 16:13:11 +02:00
|
|
|
))}
|
2023-08-26 18:23:22 +02:00
|
|
|
</div>
|
2023-08-26 16:13:11 +02:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-09-26 12:44:12 +02:00
|
|
|
export const BookmarkedSetPicker = ({ design, clickHandler, t, size, href }) => {
|
|
|
|
// Hooks
|
2023-09-26 13:58:06 +02:00
|
|
|
const { control } = useAccount()
|
2023-09-26 12:44:12 +02:00
|
|
|
const backend = useBackend()
|
|
|
|
|
|
|
|
// State
|
|
|
|
const [sets, setSets] = useState({})
|
|
|
|
|
|
|
|
// Effects
|
|
|
|
useEffect(() => {
|
|
|
|
const getBookmarks = async () => {
|
|
|
|
const result = await backend.getBookmarks()
|
2023-09-26 14:12:45 +02:00
|
|
|
const loadedSets = {}
|
2023-09-26 14:05:48 +02:00
|
|
|
if (result.success) {
|
|
|
|
for (const bookmark of result.data.bookmarks.filter(
|
|
|
|
(bookmark) => bookmark.type === 'set'
|
|
|
|
)) {
|
|
|
|
let set
|
|
|
|
try {
|
|
|
|
set = await backend.getSet(bookmark.url.slice(6))
|
|
|
|
if (set.success) {
|
|
|
|
const [hasMeasies] = hasRequiredMeasurements(
|
|
|
|
designMeasurements[design],
|
|
|
|
set.data.set.measies,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
loadedSets[set.data.set.id] = { ...set.data.set, hasMeasies }
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
2023-09-26 12:44:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setSets(loadedSets)
|
|
|
|
}
|
|
|
|
getBookmarks()
|
2023-09-26 14:05:48 +02:00
|
|
|
}, [])
|
2023-09-26 12:44:12 +02:00
|
|
|
|
|
|
|
const okSets = Object.values(sets).filter((set) => set.hasMeasies)
|
|
|
|
const lackingSets = Object.values(sets).filter((set) => !set.hasMeasies)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{okSets.length > 0 && (
|
|
|
|
<div className="flex flex-row flex-wrap gap-2">
|
|
|
|
{okSets.map((set) => (
|
|
|
|
<MsetButton
|
|
|
|
{...{ set, control, design }}
|
|
|
|
onClick={clickHandler}
|
|
|
|
href={href}
|
|
|
|
requiredMeasies={designMeasurements[design]}
|
|
|
|
key={set.id}
|
|
|
|
size={size}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{lackingSets.length > 0 && (
|
|
|
|
<div className="my-4">
|
|
|
|
<Popout note compact>
|
|
|
|
{t('account:someSetsLacking')}
|
|
|
|
</Popout>
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 2xl:grid-cols-3 gap-2">
|
|
|
|
{lackingSets.map((set) => (
|
|
|
|
<MsetLink
|
|
|
|
{...{ set, control, design }}
|
|
|
|
onClick={clickHandler}
|
|
|
|
requiredMeasies={designMeasurements[design]}
|
|
|
|
key={set.id}
|
|
|
|
size={size}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2023-08-26 16:13:11 +02:00
|
|
|
|
2023-09-03 17:53:19 +02:00
|
|
|
const SuggestCset = ({ mset, backend, setLoadingStatus, t }) => {
|
|
|
|
// State
|
|
|
|
const [height, setHeight] = useState('')
|
|
|
|
const [img, setImg] = useState('')
|
|
|
|
const [name, setName] = useState('')
|
|
|
|
const [notes, setNotes] = useState('')
|
|
|
|
const [submission, setSubmission] = useState(false)
|
|
|
|
|
|
|
|
// Method to submit the form
|
|
|
|
const suggestSet = async () => {
|
|
|
|
setLoadingStatus([true, 'status:contactingBackend'])
|
|
|
|
const result = await backend.suggestCset({ set: mset.id, height, img, name, notes })
|
|
|
|
if (result.success && result.data.submission) {
|
|
|
|
setSubmission(result.data.submission)
|
|
|
|
setLoadingStatus([true, 'status:nailedIt', true, true])
|
|
|
|
} else setLoadingStatus([true, 'backendError', true, false])
|
|
|
|
}
|
|
|
|
|
|
|
|
const missing = []
|
|
|
|
for (const m of measurements) {
|
|
|
|
if (typeof mset.measies[m] === 'undefined') missing.push(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (submission) {
|
|
|
|
const url = `/curate/sets/suggested/${submission.id}`
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h2>{t('account:thankYouVeryMuch')}</h2>
|
|
|
|
<p>{t('account:csetSuggestedMsg')}</p>
|
|
|
|
<p>
|
|
|
|
{t('account:itIsAvailableAt')}: <PageLink href={url} txt={url} />
|
|
|
|
</p>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h2>{t('account:suggestCset')}</h2>
|
|
|
|
<h4 className="flex flex-row items-center gap-2">
|
|
|
|
{missing.length > 0 ? <BoolNoIcon /> : <BoolYesIcon />}
|
|
|
|
{t('account:measurements')}
|
|
|
|
</h4>
|
|
|
|
{missing.length > 0 ? (
|
|
|
|
<>
|
|
|
|
<p>{t('account:csetAllMeasies')}</p>
|
|
|
|
<p>{t('account:csetMissing')}:</p>
|
|
|
|
<ul className="list list-inside list-disc ml-4">
|
|
|
|
{missing.map((m) => (
|
|
|
|
<li key={m}>{t(`measurements:${m}`)}</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<p>{t('account:allMeasiesAvailable')}</p>
|
|
|
|
)}
|
|
|
|
<h4 className="flex flex-row items-center gap-2">
|
|
|
|
{name.length > 1 ? <BoolYesIcon /> : <BoolNoIcon />}
|
|
|
|
{t('account:name')}
|
|
|
|
</h4>
|
|
|
|
<p>{t('account:csetNameMsg')}</p>
|
|
|
|
<StringInput
|
|
|
|
label={t('account:name')}
|
|
|
|
current={name}
|
|
|
|
update={setName}
|
|
|
|
valid={(val) => val.length > 1}
|
|
|
|
/>
|
|
|
|
<h4 className="flex flex-row items-center gap-2">
|
|
|
|
{height.length > 1 ? <BoolYesIcon /> : <BoolNoIcon />}
|
|
|
|
{t('measurements:height')}
|
|
|
|
</h4>
|
|
|
|
<p>{t('account:csetHeightMsg1')}</p>
|
|
|
|
<StringInput
|
|
|
|
label={t('measurements:height')}
|
|
|
|
current={height}
|
|
|
|
update={setHeight}
|
|
|
|
valid={(val) => val.length > 1}
|
|
|
|
/>
|
|
|
|
<h4 className="flex flex-row items-center gap-2 mt-4">
|
|
|
|
{img.length > 0 ? <BoolYesIcon /> : <BoolNoIcon />}
|
|
|
|
{t('account:img')}
|
|
|
|
</h4>
|
|
|
|
<p>
|
2023-10-25 20:15:24 +02:00
|
|
|
{t('account:csetImgMsg')}:{' '}
|
|
|
|
<PageLink href="/docs/about/site/csets">{t('account:docs')}</PageLink>
|
2023-09-03 17:53:19 +02:00
|
|
|
</p>
|
|
|
|
<PassiveImageInput
|
|
|
|
label={t('account:img')}
|
|
|
|
current={img}
|
|
|
|
update={setImg}
|
|
|
|
valid={(val) => val.length > 1}
|
|
|
|
/>
|
|
|
|
<h4 className="flex flex-row items-center gap-2 mt-4">
|
|
|
|
<BoolYesIcon />
|
|
|
|
{t('account:notes')}
|
|
|
|
</h4>
|
2023-10-04 19:24:41 +02:00
|
|
|
<p>{t('account:csetNotesMsg')}</p>
|
2023-09-03 17:53:19 +02:00
|
|
|
<Popout tip compact>
|
|
|
|
{t('account:mdSupport')}
|
|
|
|
</Popout>
|
|
|
|
<MarkdownInput
|
|
|
|
label={t('account:notes')}
|
|
|
|
current={notes}
|
|
|
|
update={setNotes}
|
|
|
|
valid={() => true}
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
className="btn btn-primary w-full mt-4"
|
|
|
|
disabled={!(missing.length === 0 && height.length > 1 && img.length > 0)}
|
|
|
|
onClick={suggestSet}
|
|
|
|
>
|
|
|
|
{t('account:suggestForCuration')}
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|