// Dependencies import { useState, useEffect, useContext, useCallback } from 'react' import { useTranslation } from 'next-i18next' import orderBy from 'lodash.orderby' import { capitalize } from 'shared/utils.mjs' import { freeSewingConfig as conf } from 'shared/config/freesewing.config.mjs' // Hooks import { useDropzone } from 'react-dropzone' import { useAccount } from 'shared/hooks/use-account.mjs' import { useBackend } from 'shared/hooks/use-backend.mjs' import { useToast } from 'shared/hooks/use-toast.mjs' import { useRouter } from 'next/router' // Context import { LoadingContext } from 'shared/context/loading-context.mjs' import { ModalContext } from 'shared/context/modal-context.mjs' // Components import { PageLink, Link } from 'shared/components/link.mjs' import { Collapse, MimicCollapseLink } from 'shared/components/collapse.mjs' import { BackToAccountButton, Choice } from './shared.mjs' import { OkIcon, NoIcon, TrashIcon, SettingsIcon, DownloadIcon, PageIcon, } from 'shared/components/icons.mjs' import { ModalWrapper } from 'shared/components/wrappers/modal.mjs' import Markdown from 'react-markdown' import { Tab } from './bio.mjs' import Timeago from 'react-timeago' import { Spinner } from 'shared/components/spinner.mjs' export const ns = ['account', 'patterns', 'toast'] export const StandAloneNewSet = () => { const { t } = useTranslation(['account']) const toast = useToast() const { account } = useAccount() const backend = useBackend() return (
) } export const NewSet = ({ t, refresh, closeCollapseButton, backend, toast, title = true, standalone = false, }) => { // Context const { startLoading, stopLoading } = useContext(LoadingContext) // Hooks const router = useRouter() // State const [name, setName] = useState('') // Helper method to create a new set const createSet = async () => { startLoading() const result = await backend.createSet({ name, }) if (result.success) { toast.success({t('nailedIt')}) if (standalone) router.push('/account/sets/') else { refresh() closeCollapseButton() } } else toast.for.backendError() stopLoading() } return (
{title ?

{t('newSet')}

: null}
{t('name')}

{t('setNameDesc')}

setName(evt.target.value)} className="input w-full input-bordered flex flex-row" type="text" placeholder={'Georg Cantor'} />
) } const EditField = (props) => { if (props.field === 'name') return if (props.field === 'notes') return if (props.field === 'public') return if (props.field === 'img') return return

FIXME: No edit component for this field

} export const EditRow = (props) => (
{props.title}
{props.children}
} >
) const EditImg = ({ t, pattern, account, backend, toast, refresh }) => { const [img, setImg] = useState(pattern.img) const { startLoading, stopLoading } = useContext(LoadingContext) const onDrop = useCallback((acceptedFiles) => { const reader = new FileReader() reader.onload = () => { setImg(reader.result) } acceptedFiles.forEach((file) => reader.readAsDataURL(file)) }, []) const { getRootProps, getInputProps } = useDropzone({ onDrop }) const save = async () => { startLoading() const result = await backend.updatePattern(pattern.id, { img }) if (result.success) { toast.for.settingsSaved() refresh() } else toast.for.backendError() stopLoading() } return (
img

{t('imgDragAndDropImageHere')}

{t('or')}

) } const EditName = ({ t, pattern, backend, toast, refresh }) => { const [value, setValue] = useState(pattern.name) const { loading, startLoading, stopLoading } = useContext(LoadingContext) const update = async (evt) => { evt.preventDefault() if (evt.target.value !== value) { setValue(evt.target.value) } } const save = async () => { startLoading() const result = await backend.updatePattern(pattern.id, { name: value }) if (result.success) { refresh() toast.for.settingsSaved() } else toast.for.backendError() stopLoading() } return (
) } const EditNotes = ({ t, pattern, backend, toast, refresh }) => { const [value, setValue] = useState(pattern.notes) const [activeTab, setActiveTab] = useState('edit') const { loading, startLoading, stopLoading } = useContext(LoadingContext) const update = async (evt) => { evt.preventDefault() if (evt.target.value !== value) { setValue(evt.target.value) } } const save = async () => { startLoading() const result = await backend.updatePattern(pattern.id, { notes: value }) if (result.success) { refresh() toast.for.settingsSaved() } else toast.for.backendError() stopLoading() } // Shared props for tabs const tabProps = { activeTab, setActiveTab, t } return (
{activeTab === 'edit' ? (