|
1 | 1 | import React, { FC, useCallback } from "react";
|
2 | 2 | import styled, { keyframes } from "styled-components";
|
3 | 3 | import { setRendererRect } from "../store/actions";
|
4 |
| -import { IStyledProps } from "../models"; |
| 4 | +import { DocRenderer, IConfig, IDocument, IStyledProps } from "../models"; |
5 | 5 | import { getFileName } from "../utils/getFileName";
|
6 | 6 | import { useDocumentLoader } from "../hooks/useDocumentLoader";
|
7 | 7 | import { useWindowSize } from "../hooks/useWindowSize";
|
8 | 8 | import { LinkButton } from "./common";
|
9 | 9 | import { LoadingIcon } from "./icons";
|
10 | 10 | import { LoadingTimeout } from "./LoadingTimout";
|
11 | 11 | import { useTranslation } from "../hooks/useTranslation";
|
| 12 | +import { IMainState } from "../store/mainStateReducer"; |
12 | 13 |
|
13 |
| -export const ProxyRenderer: FC = () => { |
14 |
| - const { state, dispatch, CurrentRenderer } = useDocumentLoader(); |
15 |
| - const { documents, documentLoading, currentDocument, config } = state; |
16 |
| - const size = useWindowSize(); |
17 |
| - const { t } = useTranslation(); |
18 |
| - |
19 |
| - const containerRef = useCallback( |
20 |
| - (node: HTMLDivElement) => { |
21 |
| - node && dispatch(setRendererRect(node?.getBoundingClientRect())); |
22 |
| - }, |
23 |
| - // eslint-disable-next-line react-hooks/exhaustive-deps |
24 |
| - [size], |
25 |
| - ); |
| 14 | +type ContentsProps = { |
| 15 | + documents: IDocument[]; |
| 16 | + documentLoading: boolean | undefined; |
| 17 | + config: IConfig | undefined; |
| 18 | + currentDocument: IDocument | undefined; |
| 19 | + fileName: string; |
| 20 | + CurrentRenderer: DocRenderer | null | undefined; |
| 21 | + state: IMainState; |
| 22 | + t: (key: "noRendererMessage" | "documentNavInfo" | "downloadButtonLabel" | "brokenFile" | "msgPluginRecipients" | "msgPluginSender" | "pdfPluginLoading" | "pdfPluginPageNumber", variables?: Record<string, string | number>) => string |
| 23 | +}; |
26 | 24 |
|
27 |
| - const fileName = getFileName( |
28 |
| - currentDocument, |
29 |
| - config?.header?.retainURLParams || false, |
30 |
| - ); |
| 25 | + const Contents: React.FC<ContentsProps> = ({documents, documentLoading, config, currentDocument, fileName, CurrentRenderer, state, t}) => { |
31 | 26 |
|
32 |
| - const Contents = () => { |
33 | 27 | if (!documents.length) {
|
34 | 28 | return <div id="no-documents"></div>;
|
35 | 29 | } else if (documentLoading) {
|
@@ -85,13 +79,31 @@ export const ProxyRenderer: FC = () => {
|
85 | 79 | }
|
86 | 80 | };
|
87 | 81 |
|
| 82 | +export const ProxyRenderer: FC = () => { |
| 83 | + const { state, dispatch, CurrentRenderer } = useDocumentLoader(); |
| 84 | + const { documents, documentLoading, currentDocument, config } = state; |
| 85 | + const size = useWindowSize(); |
| 86 | + const { t } = useTranslation(); |
| 87 | + |
| 88 | + const containerRef = useCallback( |
| 89 | + (node: HTMLDivElement) => { |
| 90 | + node && dispatch(setRendererRect(node?.getBoundingClientRect())); |
| 91 | + }, |
| 92 | + [size], |
| 93 | + ); |
| 94 | + |
| 95 | + const fileName = getFileName( |
| 96 | + currentDocument, |
| 97 | + config?.header?.retainURLParams || false, |
| 98 | + ); |
| 99 | + |
88 | 100 | return (
|
89 | 101 | <Container
|
90 | 102 | id="proxy-renderer"
|
91 | 103 | data-testid="proxy-renderer"
|
92 | 104 | ref={containerRef}
|
93 | 105 | >
|
94 |
| - <Contents /> |
| 106 | + <Contents {...{state, documents, documentLoading, config, currentDocument, fileName, CurrentRenderer, t}} /> |
95 | 107 | </Container>
|
96 | 108 | );
|
97 | 109 | };
|
|
0 commit comments