diff --git a/src/current/features/pdfDownload/S89DownloadPDF.jsx b/src/current/features/pdfDownload/S89DownloadPDF.jsx index 00f1a2bb6e..7e6a0e0851 100644 --- a/src/current/features/pdfDownload/S89DownloadPDF.jsx +++ b/src/current/features/pdfDownload/S89DownloadPDF.jsx @@ -1,5 +1,5 @@ import { useCallback, useEffect } from 'react'; -import { useRecoilState, useRecoilValue } from 'recoil'; +import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil'; import { usePDF } from '@react-pdf/renderer'; import Box from '@mui/material/Box'; import CircularProgress from '@mui/material/CircularProgress'; @@ -8,23 +8,14 @@ import DialogContent from '@mui/material/DialogContent'; import { S89 } from '../../views'; import { S89DownloadLoadingState, S89DownloadOpenState, s89DataState } from '../../states/schedule'; -const S89DownloadPDF = () => { - const [open, setOpen] = useRecoilState(S89DownloadOpenState); - - const s89Data = useRecoilValue(s89DataState); - const isLoading = useRecoilValue(S89DownloadLoadingState); +const Download = ({ s89Data }) => { + const setOpen = useSetRecoilState(S89DownloadOpenState); + const setisLoading = useSetRecoilState(S89DownloadLoadingState); const [instance, update] = usePDF({ document: , }); - const handleClose = (event, reason) => { - if (reason === 'clickaway' || reason === 'backdropClick') { - return; - } - setOpen(false); - }; - const handleRerenderPDF = useCallback(async () => { await update(); if (instance.url) { @@ -34,40 +25,63 @@ const S89DownloadPDF = () => { document.body.appendChild(link); link.click(); document.body.removeChild(link); - setOpen(false); } + setOpen(false); }, [update, instance.url, setOpen]); + useEffect(() => { + setisLoading(instance.loading); + }, [instance.loading, setisLoading]); + useEffect(() => { const updatePDF = setTimeout(async () => { - if (!isLoading) await handleRerenderPDF(); + handleRerenderPDF(); }, 3000); return () => { clearTimeout(updatePDF); }; - }, [isLoading, handleRerenderPDF]); + }, [handleRerenderPDF]); + + return <>; +}; + +const S89DownloadPDF = () => { + const [open, setOpen] = useRecoilState(S89DownloadOpenState); + + const s89Data = useRecoilValue(s89DataState); + const isLoading = useRecoilValue(S89DownloadLoadingState); + + const handleClose = (event, reason) => { + if (reason === 'clickaway' || reason === 'backdropClick') { + return; + } + setOpen(false); + }; return ( - - - - - + {isLoading && ( + + + + + + )} + {s89Data.length > 0 && } ); }; diff --git a/src/current/features/schedules/S89Selector.jsx b/src/current/features/schedules/S89Selector.jsx index 51ce99fb3f..eae0f637fd 100644 --- a/src/current/features/schedules/S89Selector.jsx +++ b/src/current/features/schedules/S89Selector.jsx @@ -41,6 +41,7 @@ const S89Selector = () => { const handlePreviewS89 = async () => { setIsS89DownloadLoading(true); setIsS89Download(true); + const realData = selected.filter((item) => item.length > 10); realData.sort((a, b) => { return a > b ? 1 : -1;