|
3 | 3 | the iFrameRef is not really compatiple with ts,
|
4 | 4 | */
|
5 | 5 |
|
6 |
| -import React, { useEffect, useRef, useState } from 'react' |
| 6 | +import React, { useEffect, useRef, useMemo, useState } from 'react' |
7 | 7 | import { useLocation, useParams, useSearchParams } from 'react-router-dom'
|
8 | 8 | import DocumentControlButtons from '../components/DocumentControlButtons'
|
9 | 9 | import ProjectDetails from '../models/ProjectDetails'
|
@@ -36,22 +36,29 @@ export default function Docs (): JSX.Element {
|
36 | 36 | const location = useLocation()
|
37 | 37 | const iFrameRef = useRef<HTMLIFrameElement>(null)
|
38 | 38 |
|
| 39 | + const iFrame = useMemo(() => { |
| 40 | + return (<iframe |
| 41 | + ref={iFrameRef} |
| 42 | + key={uniqueId()} |
| 43 | + src={ProjectRepository.getProjectDocsURL(project, version, page, hash)} |
| 44 | + title="docs" |
| 45 | + className={styles['docs-iframe']} |
| 46 | + onLoad={() => { |
| 47 | + // @ts-expect-error ts can't find contentWindow |
| 48 | + onIFrameLocationChanged(iFrameRef.current?.contentWindow.location.href) |
| 49 | + }} |
| 50 | + /> |
| 51 | + ) |
| 52 | + }, [project, version, page]) |
| 53 | + |
39 | 54 | document.title = `${project} | docat`
|
40 | 55 |
|
41 | 56 | if (projectParam === '') {
|
42 | 57 | setLoadingFailed(true)
|
43 | 58 | }
|
44 | 59 |
|
45 | 60 | const updateURL = (newProject: string, newVersion: string, newPage: string, newHash: string, newHideUi: boolean): void => {
|
46 |
| - let url = `#/${newProject}/${newVersion}/${newPage}` |
47 |
| - |
48 |
| - if (newHash.length > 0) { |
49 |
| - url += newHash |
50 |
| - } |
51 |
| - |
52 |
| - if (newHideUi) { |
53 |
| - url += '?hide-ui=true' |
54 |
| - } |
| 61 | + const url = `#/${newProject}/${newVersion}/${newPage}${newHash}${newHideUi ? '?hide-ui=true' : ''}` |
55 | 62 |
|
56 | 63 | if (project === newProject && version === newVersion && page === newPage && hash === newHash && hideUi === newHideUi) {
|
57 | 64 | // no change
|
@@ -217,18 +224,7 @@ export default function Docs (): JSX.Element {
|
217 | 224 |
|
218 | 225 | return (
|
219 | 226 | <>
|
220 |
| - <iframe |
221 |
| - ref={iFrameRef} |
222 |
| - key={uniqueId()} |
223 |
| - src={ProjectRepository.getProjectDocsURL(project, version, page, hash)} |
224 |
| - title="docs" |
225 |
| - className={styles['docs-iframe']} |
226 |
| - onLoad={() => { |
227 |
| - // @ts-expect-error ts can't find contentWindow |
228 |
| - onIFrameLocationChanged(iFrameRef.current?.contentWindow.location.href) |
229 |
| - }} |
230 |
| - /> |
231 |
| - |
| 227 | + {iFrame} |
232 | 228 | {!hideUi && (
|
233 | 229 | <DocumentControlButtons
|
234 | 230 | version={version}
|
|
0 commit comments