From eed04910f4960febfe9441fa1ff2a85f2f35f838 Mon Sep 17 00:00:00 2001 From: Rob Ellison Date: Wed, 17 May 2023 17:51:25 +0000 Subject: [PATCH] fix: fix re-rendering --- layouts/SlidePage.jsx | 2 +- pages/output/[...parms].jsx | 103 ++++++++++++++++++++---------------- 2 files changed, 57 insertions(+), 48 deletions(-) diff --git a/layouts/SlidePage.jsx b/layouts/SlidePage.jsx index 140dc553..d48b7164 100644 --- a/layouts/SlidePage.jsx +++ b/layouts/SlidePage.jsx @@ -101,7 +101,7 @@ function SlidePage({ children, next }) { // Handle next page if (NEXT.indexOf(keyCode) !== -1 && currentSlide === slideCount) { if (router.query && router.pathname && next) { - router.push(`${next}?mode=${mode}`); + router.push(`${next}?format=ppt&mode=${mode}`); } return false; } diff --git a/pages/output/[...parms].jsx b/pages/output/[...parms].jsx index 39386180..2961d527 100644 --- a/pages/output/[...parms].jsx +++ b/pages/output/[...parms].jsx @@ -148,49 +148,64 @@ function Page() { mdx = '\n' + content + '\n' } else if (format === 'doc') { mdx = '
\n' + content.replace(/---/g, '') + '\n
' - mdx = matter.stringify(mdx, { ...frontmatter }); } else if (format === 'print') { mdx = '\n' + content + '\n' } else { mdx = removeSection(mdx, 'TitleSlide'); mdx = '\n' + content.replace(/---/g, '') + '\n' } + mdx = matter.stringify(mdx, { ...frontmatter }); return mdx } - + + + // Create a preview component that can handle errors with try-catch block; for catching invalid JS expressions errors that ErrorBoundary cannot catch. + const Preview = useCallback(() => { + try { + return state.file.result() + } catch (error) { + // console.log('/output:Preview:useCallback:Error: ', error) + return + } + }, [state]) // const stats = state.file ? statistics(state.file) : {} useEffect(() => { const fetchFileContent = async () => { - if (source === 'file') { - fetch(`/api/files/file?filePath=${location}`) - .then((res) => res.json()) - .then(data => { - if (data.content) { - // console.log('/output/[...params].jsx:useEffect:router.query: ', router.query) - - // console.log('/output/[...params].jsx:useEffect:content: ', mdxContent(format, data.content, router.query)) - - setConfig({ ...state, value: String(mdxContent(format, data.content, router.query)) }) - } else if (error) { - // console.log('output:error: ', error) - } else { - // console.log('output:error: unknown error') - } - }) - .catch(error => { - // console.log(error) - return { fileData: null, error: error } - }) - .finally(() => { - // console.log('no timeout') - }); - } else { - // console.log('output:error: no source defined') - } + fetch(`/api/files/file?filePath=${location}`) + .then((res) => res.json()) + .then(data => { + if (data.content) { + // console.log('/output/[...params].jsx:useEffect:router.query: ', router.query) + // console.log('/output/[...params].jsx:useEffect:content: ', mdxContent(format, data.content, router.query)) + + setConfig({ ...state, value: String(mdxContent(format, data.content, router.query)) }) + } else if (error) { + // console.log('output:error: ', error) + } else { + // console.log('output:error: unknown error') + } + }) + .catch(error => { + // console.log(error) + return { fileData: null, error: error } + }) + .finally(() => { + console.log('timeout: ', refreshToken); + }); + }; + + console.log('effectloading file', router) + if (source === 'file') { + fetchFileContent() + setTimeout(() => setRefreshToken(Math.random()), 50000); + } else if (!source) { + setTimeout(() => setRefreshToken(Math.random()), 500); } + }, [refreshToken]); + useEffect(() => { const fetchPadContent = async () => { fetch(`/api/etherpad/pad-revs?pad=${location}`) .then((res) => res.json()) @@ -221,45 +236,39 @@ function Page() { }); } - if (source === 'file') {fetchFileContent()} else if (source === 'pad') {fetchPadContent()} - - }, [refreshToken, source] - ); + if (source === 'pad') { fetchPadContent() } + }, [refreshToken]); - // Create a preview component that can handle errors with try-catch block; for catching invalid JS expressions errors that ErrorBoundary cannot catch. - const Preview = useCallback(() => { - try { - return state.file.result() - } catch (error) { - // console.log('/output:Preview:useCallback:Error: ', error) - return - } - }, [state]) - if (format === 'doc') { - if (state.file && state.file.result) { // console.log('/output:PrintView:file: ', state.file.result) } + if (state.file && state.file.result) { + // console.log('/output:PrintView:file: ', state.file.result) + } return ( - {state.file && state.file.result ? () : null} + {state.file && state.file.result ? () : null} ) } else { - if (state.file && state.file.result) { // console.log('/output:DefaultView:file: ', state.file.result) } + if (state.file && state.file.result) { + // console.log('/output:DefaultView:file: ', state.file.result) + } return ( {state.file && state.file.result ? () : null} ) }; +}; + + -} // PDF Print View component -function PrintView({ children }) { +function DocumentView({ children }) { // console.log('/output:PrintView:children: ', children); const mdxContainer = useRef(null);