2022-08-24 11:03:11 -05:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-02-20 18:46:21 +01:00
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
import Settings from './settings'
|
2022-06-28 13:41:27 -05:00
|
|
|
import Draft from '../draft/index'
|
2022-10-28 15:03:04 -05:00
|
|
|
import { pagesPlugin } from './plugin'
|
|
|
|
import {
|
|
|
|
handleExport,
|
|
|
|
defaultPdfSettings,
|
|
|
|
} from 'shared/components/workbench/exporting/export-handler'
|
2022-08-24 11:03:11 -05:00
|
|
|
import Popout from 'shared/components/popout'
|
2022-02-20 18:46:21 +01:00
|
|
|
|
2022-10-28 15:03:04 -05:00
|
|
|
const PrintLayout = (props) => {
|
2022-08-14 16:50:16 -05:00
|
|
|
// disable xray
|
2022-02-20 19:02:25 +01:00
|
|
|
useEffect(() => {
|
2022-10-28 15:03:04 -05:00
|
|
|
if (props.gist?._state?.xray?.enabled) props.updateGist(['_state', 'xray', 'enabled'], false)
|
2022-11-14 16:53:31 -06:00
|
|
|
})
|
2022-02-20 19:02:25 +01:00
|
|
|
|
2022-02-20 18:46:21 +01:00
|
|
|
const { t } = useTranslation(['workbench'])
|
2022-08-24 11:03:11 -05:00
|
|
|
const [error, setError] = useState(false)
|
2022-02-20 18:46:21 +01:00
|
|
|
|
2022-08-09 16:16:06 -05:00
|
|
|
const draft = props.draft
|
2022-08-17 13:11:22 -05:00
|
|
|
|
2022-08-14 16:50:16 -05:00
|
|
|
// add the pages plugin to the draft
|
2022-08-23 11:08:40 -05:00
|
|
|
const layoutSettings = {
|
|
|
|
...defaultPdfSettings,
|
2022-10-28 15:03:04 -05:00
|
|
|
...props.gist?._state?.layout?.forPrinting?.page,
|
2022-08-23 11:08:40 -05:00
|
|
|
}
|
2022-10-28 15:03:04 -05:00
|
|
|
draft.use(pagesPlugin(layoutSettings))
|
2022-08-14 16:50:16 -05:00
|
|
|
|
2022-02-20 18:46:21 +01:00
|
|
|
let patternProps
|
|
|
|
try {
|
2022-08-14 16:50:16 -05:00
|
|
|
// draft the pattern
|
2022-02-20 18:46:21 +01:00
|
|
|
draft.draft()
|
|
|
|
patternProps = draft.getRenderProps()
|
2022-10-28 15:03:04 -05:00
|
|
|
} catch (err) {
|
2022-03-06 18:54:30 +01:00
|
|
|
console.log(err, props.gist)
|
2022-02-20 18:46:21 +01:00
|
|
|
}
|
2022-10-28 15:03:04 -05:00
|
|
|
const bgProps = { fill: 'url(#page)' }
|
2022-02-20 18:46:21 +01:00
|
|
|
|
2022-08-16 00:33:35 -05:00
|
|
|
const exportIt = () => {
|
2022-08-24 11:03:11 -05:00
|
|
|
setError(false)
|
2022-10-28 15:03:04 -05:00
|
|
|
handleExport(
|
|
|
|
'pdf',
|
|
|
|
props.gist,
|
|
|
|
props.design,
|
|
|
|
t,
|
|
|
|
props.app,
|
2022-11-14 16:53:31 -06:00
|
|
|
() => setError(false),
|
|
|
|
() => setError(true)
|
2022-10-28 15:03:04 -05:00
|
|
|
)
|
2022-08-16 00:33:35 -05:00
|
|
|
}
|
|
|
|
|
2022-09-25 10:45:52 +02:00
|
|
|
let name = props.design.designConfig.data.name
|
2022-09-01 22:58:26 -07:00
|
|
|
name = name.replace('@freesewing/', '')
|
2022-02-20 18:46:21 +01:00
|
|
|
return (
|
|
|
|
<div>
|
2022-10-28 15:03:04 -05:00
|
|
|
<h2 className="capitalize">{t('layoutThing', { thing: name }) + ': ' + t('forPrinting')}</h2>
|
2022-02-20 18:46:21 +01:00
|
|
|
<div className="m-4">
|
2022-10-28 15:03:04 -05:00
|
|
|
<Settings {...{ ...props, exportIt, layoutSettings }} draft={draft} />
|
2022-08-24 11:03:11 -05:00
|
|
|
{error && (
|
|
|
|
<Popout warning compact>
|
2022-10-28 15:03:04 -05:00
|
|
|
<span className="font-bold mr-4 uppercase text-sm">{t('error')}:</span>
|
2022-08-24 11:03:11 -05:00
|
|
|
{t('somethingWentWrong')}
|
|
|
|
</Popout>
|
|
|
|
)}
|
2022-02-20 18:46:21 +01:00
|
|
|
</div>
|
|
|
|
<Draft
|
|
|
|
draft={draft}
|
|
|
|
gist={props.gist}
|
2022-02-25 08:30:03 +01:00
|
|
|
updateGist={props.updateGist}
|
2022-02-20 18:46:21 +01:00
|
|
|
patternProps={patternProps}
|
|
|
|
bgProps={bgProps}
|
2022-06-28 02:02:51 -05:00
|
|
|
gistReady={props.gistReady}
|
2022-08-09 16:16:06 -05:00
|
|
|
layoutPart="pages"
|
2022-02-20 18:46:21 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PrintLayout
|