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

70 lines
2 KiB
JavaScript
Raw Normal View History

2023-06-06 15:19:11 -05:00
import { useState, useContext } from 'react'
import { useTranslation } from 'next-i18next'
import { Popout } from 'shared/components/popout.mjs'
import { WebLink } from 'shared/components/web-link.mjs'
2023-06-06 15:19:11 -05:00
import { LoadingContext } from 'shared/context/loading-context.mjs'
import { useToast } from 'shared/hooks/use-toast.mjs'
import {
exportTypes,
handleExport,
ns as exportNs,
} from 'shared/components/workbench/exporting/export-handler.mjs'
2023-06-06 15:19:11 -05:00
export const ns = ['exporting', exportNs]
export const ExportView = ({ settings, ui, design, Design }) => {
const [link, setLink] = useState(false)
const [format, setFormat] = useState(false)
2023-06-06 15:25:23 -05:00
const { startLoading, stopLoading } = useContext(LoadingContext)
2023-06-06 15:19:11 -05:00
const toast = useToast()
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) => {
if (e.data?.error) toast.error(e.data.error.message)
},
})
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">
<h2>{t('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) => (
<button key={format} className="btn btn-primary" onClick={() => doExport(format)}>
{type === 'exportForPrinting' ? `${format} pdf` : format}
</button>
))}
</div>
))}
</div>
</div>
)
}