Skip to content

Commit

Permalink
Merge pull request #205 from hlouzek/rerendering
Browse files Browse the repository at this point in the history
When I wanted to extend props with my own values, there was unwanted …
  • Loading branch information
cyntler authored Jan 28, 2024
2 parents b9d9d28 + 1be9e85 commit b02c6bd
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions src/components/ProxyRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
import React, { FC, useCallback } from "react";
import styled, { keyframes } from "styled-components";
import { setRendererRect } from "../store/actions";
import { IStyledProps } from "../models";
import { DocRenderer, IConfig, IDocument, IStyledProps } from "../models";
import { getFileName } from "../utils/getFileName";
import { useDocumentLoader } from "../hooks/useDocumentLoader";
import { useWindowSize } from "../hooks/useWindowSize";
import { LinkButton } from "./common";
import { LoadingIcon } from "./icons";
import { LoadingTimeout } from "./LoadingTimout";
import { useTranslation } from "../hooks/useTranslation";
import { IMainState } from "../store/mainStateReducer";

export const ProxyRenderer: FC = () => {
const { state, dispatch, CurrentRenderer } = useDocumentLoader();
const { documents, documentLoading, currentDocument, config } = state;
const size = useWindowSize();
const { t } = useTranslation();

const containerRef = useCallback(
(node: HTMLDivElement) => {
node && dispatch(setRendererRect(node?.getBoundingClientRect()));
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[size],
);
type ContentsProps = {
documents: IDocument[];
documentLoading: boolean | undefined;
config: IConfig | undefined;
currentDocument: IDocument | undefined;
fileName: string;
CurrentRenderer: DocRenderer | null | undefined;
state: IMainState;
t: (key: "noRendererMessage" | "documentNavInfo" | "downloadButtonLabel" | "brokenFile" | "msgPluginRecipients" | "msgPluginSender" | "pdfPluginLoading" | "pdfPluginPageNumber", variables?: Record<string, string | number>) => string
};

const fileName = getFileName(
currentDocument,
config?.header?.retainURLParams || false,
);
const Contents: React.FC<ContentsProps> = ({documents, documentLoading, config, currentDocument, fileName, CurrentRenderer, state, t}) => {

const Contents = () => {
if (!documents.length) {
return <div id="no-documents"></div>;
} else if (documentLoading) {
Expand Down Expand Up @@ -85,13 +79,31 @@ export const ProxyRenderer: FC = () => {
}
};

export const ProxyRenderer: FC = () => {
const { state, dispatch, CurrentRenderer } = useDocumentLoader();
const { documents, documentLoading, currentDocument, config } = state;
const size = useWindowSize();
const { t } = useTranslation();

const containerRef = useCallback(
(node: HTMLDivElement) => {
node && dispatch(setRendererRect(node?.getBoundingClientRect()));
},
[size],
);

const fileName = getFileName(
currentDocument,
config?.header?.retainURLParams || false,
);

return (
<Container
id="proxy-renderer"
data-testid="proxy-renderer"
ref={containerRef}
>
<Contents />
<Contents {...{state, documents, documentLoading, config, currentDocument, fileName, CurrentRenderer, t}} />
</Container>
);
};
Expand Down

0 comments on commit b02c6bd

Please sign in to comment.