1
0
Fork 0
freesewing/sites/shared/components/workbench/views/exporting/index.mjs

80 lines
2.4 KiB
JavaScript
Raw Normal View History

2023-09-29 16:01:27 +02:00
// __SDEFILE__ - This file is a dependency for the stand-alone environment
2023-09-04 08:40:05 +02:00
// Dependencies
2023-06-06 15:19:11 -05:00
import {
exportTypes,
handleExport,
ns as exportNs,
} from 'shared/components/workbench/exporting/export-handler.mjs'
2023-09-04 08:40:05 +02:00
// Context
import { LoadingStatusContext } from 'shared/context/loading-status-context.mjs'
// Hooks
import { useState, useContext } from 'react'
import { useTranslation } from 'next-i18next'
// Components
import { Popout } from 'shared/components/popout/index.mjs'
import { WebLink } from 'shared/components/link.mjs'
2023-11-03 19:41:21 +01:00
export const ns = ['exporting', exportNs, 'workbench']
2023-06-06 15:19:11 -05:00
export const ExportView = ({ settings, ui, design, Design }) => {
const [link, setLink] = useState(false)
const [format, setFormat] = useState(false)
2023-09-04 08:40:05 +02:00
const { setLoadingStatus } = useContext(LoadingStatusContext)
const startLoading = () => setLoadingStatus([true, 'exporting'])
const stopLoading = () => setLoadingStatus([true, 'status:nailedIt', true, true])
2023-06-06 15:19:11 -05:00
const { t } = useTranslation(ns)
2022-08-21 10:26:35 +01:00
const doExport = (format) => {
setLink(false)
setFormat(format)
2023-06-06 15:19:11 -05:00
handleExport({
format,
settings,
design,
t,
Design,
ui,
startLoading,
stopLoading,
onComplete: (e) => {
if (e.data.link) {
setLink(e.data.link)
}
},
onError: (e) => {
2023-09-04 08:40:05 +02:00
if (e.data?.error) setLoadingStatus([true, e.data.error.message, true, false])
2023-06-06 15:19:11 -05:00
},
})
2022-08-21 10:26:35 +01:00
}
return (
2023-06-06 15:19:11 -05:00
<div className="max-w-screen-xl m-auto py-8">
2023-11-03 19:41:21 +01:00
<h2>{t('workbench:export')}</h2>
<p className="text-lg sm:text-xl">{t('exportPattern-txt')}</p>
{link && (
<Popout link compact>
2022-10-23 19:53:08 +02:00
<span className="font-bold mr-4 uppercase text-sm">{format}:</span>
<WebLink href={link} txt={link} />
</Popout>
)}
<div className="flex flex-row flex-wrap gap-8">
2022-10-23 19:53:08 +02:00
{Object.keys(exportTypes).map((type) => (
<div key={type} className="flex flex-col gap-2 w-full sm:w-auto">
<h4>{t(type)}</h4>
2022-10-23 19:53:08 +02:00
{exportTypes[type].map((format) => (
2023-11-03 19:41:21 +01:00
<button
key={format}
className="btn btn-primary uppercase"
onClick={() => doExport(format)}
>
2022-10-23 19:53:08 +02:00
{type === 'exportForPrinting' ? `${format} pdf` : format}
</button>
))}
</div>
))}
</div>
</div>
)
}