import { GlobalToastGeneratorEntry } from '@/features/ide-react/components/global-toasts'
import { Trans, useTranslation } from 'react-i18next'
const PreparingExportToast = () => {
const { t } = useTranslation()
return {t('preparing_for_export')}
}
const ExportDocumentErrorToast = () => {
const { t } = useTranslation()
return (
<>
{t('we_couldnt_export_this_document')}
,
]}
/>
>
)
}
const ExportDocumentSuccessToast = ({ data }: { data?: any }) => {
const type = data?.type
if (type === 'docx') {
return (
,
]}
/>
)
} else if (type === 'markdown') {
return (
,
]}
/>
)
} else {
return (
,
]}
/>
)
}
}
const generators: GlobalToastGeneratorEntry[] = [
{
key: 'export-document:error',
generator: () => ({
content: ,
type: 'error',
autoHide: true,
delay: 5000,
isDismissible: true,
}),
},
{
key: 'export-document:preparing',
generator: () => ({
content: ,
type: 'info',
autoHide: false,
isDismissible: true,
}),
},
{
key: 'export-document:success',
generator: (data: any) => ({
content: ,
type: 'success',
autoHide: true,
delay: 45000,
isDismissible: true,
}),
},
]
export default generators
export const showExportDocumentError = () => {
window.dispatchEvent(
new CustomEvent('ide:show-toast', {
detail: { key: 'export-document:error' },
})
)
}
export const showPreparingExportToast = () => {
const handle = `export-document-preparing-${Date.now()}`
window.dispatchEvent(
new CustomEvent('ide:show-toast', {
detail: { key: 'export-document:preparing', handle },
})
)
return handle
}
export const hidePreparingExportToast = (handle: string) => {
window.dispatchEvent(
new CustomEvent('ide:dismiss-toast', {
detail: { key: 'export-document:preparing', handle },
})
)
}
export const showExportDocumentSuccess = (type: 'docx' | 'markdown') => {
window.dispatchEvent(
new CustomEvent('ide:show-toast', {
detail: { key: 'export-document:success', type },
})
)
}