2022-02-13 15:45:27 +01:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-01-29 18:57:24 +01:00
|
|
|
import { svgattrPlugin } from '@freesewing/plugin-svgattr'
|
2023-05-11 19:14:48 +02:00
|
|
|
import { SvgWrapper } from './pattern/svg.mjs'
|
|
|
|
import { DraftError } from './pattern/error.mjs'
|
2022-02-13 15:45:27 +01:00
|
|
|
|
2023-01-29 18:57:24 +01:00
|
|
|
export const LabSample = ({ gist, draft, updateGist, unsetGist, showInfo, app, feedback }) => {
|
2022-02-13 15:45:27 +01:00
|
|
|
const { t } = useTranslation(['workbench'])
|
|
|
|
let svg
|
|
|
|
let title = ''
|
2022-09-17 10:30:21 +02:00
|
|
|
let patternProps
|
|
|
|
const errors = []
|
2023-02-12 11:26:25 -06:00
|
|
|
|
|
|
|
draft.use(svgattrPlugin, {
|
|
|
|
class: 'freesewing pattern max-h-screen',
|
|
|
|
})
|
|
|
|
|
2022-02-13 15:45:27 +01:00
|
|
|
if (gist.sample) {
|
|
|
|
try {
|
2022-09-17 10:30:21 +02:00
|
|
|
draft = draft.sample()
|
2023-02-12 11:41:31 -06:00
|
|
|
patternProps = draft.getRenderProps()
|
2022-09-17 10:30:21 +02:00
|
|
|
// Render as React
|
2023-02-12 11:26:25 -06:00
|
|
|
for (const logs of patternProps.logs.sets) errors.push(...logs.error)
|
2023-01-29 18:57:24 +01:00
|
|
|
} catch (err) {
|
2022-02-13 15:45:27 +01:00
|
|
|
console.log(err)
|
|
|
|
}
|
2023-02-12 11:26:25 -06:00
|
|
|
|
|
|
|
//FIXME this doesn't work for models
|
|
|
|
title = t('testThing', {
|
|
|
|
thing: ` : ${t(gist.sample.type)} : ${gist.sample[gist.sample.type]}`,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
// don't error on first page landing
|
|
|
|
draft.draft()
|
2023-02-12 11:41:31 -06:00
|
|
|
patternProps = draft.getRenderProps()
|
2022-02-13 15:45:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h2>{title}</h2>
|
2022-09-17 10:30:21 +02:00
|
|
|
{!patternProps || errors.length > 0 ? (
|
2023-02-09 21:39:19 -06:00
|
|
|
<DraftError {...{ draft, patternProps, updateGist, errors }} />
|
2022-09-17 10:30:21 +02:00
|
|
|
) : null}
|
|
|
|
<SvgWrapper
|
|
|
|
{...{ draft, patternProps, gist, updateGist, unsetGist, showInfo, app, feedback }}
|
|
|
|
/>
|
2023-01-29 18:57:24 +01:00
|
|
|
<div className="freesewing pattern" dangerouslySetInnerHTML={{ __html: svg }} />
|
2022-02-13 15:45:27 +01:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|