Skip to content

Commit b02c6bd

Browse files
authored
Merge pull request #205 from hlouzek/rerendering
When I wanted to extend props with my own values, there was unwanted …
2 parents b9d9d28 + 1be9e85 commit b02c6bd

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

src/components/ProxyRenderer.tsx

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
11
import React, { FC, useCallback } from "react";
22
import styled, { keyframes } from "styled-components";
33
import { setRendererRect } from "../store/actions";
4-
import { IStyledProps } from "../models";
4+
import { DocRenderer, IConfig, IDocument, IStyledProps } from "../models";
55
import { getFileName } from "../utils/getFileName";
66
import { useDocumentLoader } from "../hooks/useDocumentLoader";
77
import { useWindowSize } from "../hooks/useWindowSize";
88
import { LinkButton } from "./common";
99
import { LoadingIcon } from "./icons";
1010
import { LoadingTimeout } from "./LoadingTimout";
1111
import { useTranslation } from "../hooks/useTranslation";
12+
import { IMainState } from "../store/mainStateReducer";
1213

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+
};
2624

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}) => {
3126

32-
const Contents = () => {
3327
if (!documents.length) {
3428
return <div id="no-documents"></div>;
3529
} else if (documentLoading) {
@@ -85,13 +79,31 @@ export const ProxyRenderer: FC = () => {
8579
}
8680
};
8781

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+
88100
return (
89101
<Container
90102
id="proxy-renderer"
91103
data-testid="proxy-renderer"
92104
ref={containerRef}
93105
>
94-
<Contents />
106+
<Contents {...{state, documents, documentLoading, config, currentDocument, fileName, CurrentRenderer, t}} />
95107
</Container>
96108
);
97109
};

0 commit comments

Comments
 (0)