Enhance TemplatePreview with Clear Iframe Contents Functionality
- Added a new function to clear iframe contents, improving resource management and preventing stale data display. - Integrated the clearIframeContents function into the PDF preview type change handler, ensuring a clean slate when switching to PDF previews. - Updated state management for iframe size and preview content to enhance user experience and maintain consistency.
This commit is contained in:
parent
9766f4b6c3
commit
47e4e60b86
@ -171,6 +171,19 @@ const TemplatePreview = ({
|
|||||||
setPreviewContentHTML(html)
|
setPreviewContentHTML(html)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clearIframeContents = useCallback(() => {
|
||||||
|
iframeSizeObserverRef.current?.disconnect()
|
||||||
|
iframeSizeObserverRef.current = null
|
||||||
|
|
||||||
|
const iframe = iframeRef.current
|
||||||
|
if (iframe) {
|
||||||
|
iframe.srcdoc = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
setPreviewContentHTML('')
|
||||||
|
setIframeSize({ width: '100%', height: 'auto' })
|
||||||
|
}, [])
|
||||||
|
|
||||||
const stopRenderProgressListener = useCallback(() => {
|
const stopRenderProgressListener = useCallback(() => {
|
||||||
if (typeof renderUnsubscribeRef.current === 'function') {
|
if (typeof renderUnsubscribeRef.current === 'function') {
|
||||||
renderUnsubscribeRef.current()
|
renderUnsubscribeRef.current()
|
||||||
@ -541,10 +554,11 @@ const TemplatePreview = ({
|
|||||||
disabled={loading || reloadLoading}
|
disabled={loading || reloadLoading}
|
||||||
value={previewType}
|
value={previewType}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
setPreviewType(value)
|
|
||||||
if (value == 'PDF') {
|
if (value == 'PDF') {
|
||||||
|
clearIframeContents()
|
||||||
setPDFBlob(null)
|
setPDFBlob(null)
|
||||||
}
|
}
|
||||||
|
setPreviewType(value)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user