Skip to content

Commit

Permalink
fix: preview content container resize
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Jul 21, 2023
1 parent 9d3f682 commit 325a153
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/app/modules/report-module/views/preview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { useRecoilState } from "recoil";
import Box from "@material-ui/core/Box";
import { useParams } from "react-router-dom";
import useResizeObserver from "use-resize-observer";
import Container from "@material-ui/core/Container";
import { EditorState, convertFromRaw } from "draft-js";
import { useStoreActions, useStoreState } from "app/state/store/hooks";
Expand All @@ -13,17 +14,24 @@ import {
reportContentWidthsAtom,
reportContentHeightsAtom,
persistedReportStateAtom,
reportContentContainerWidth,
unSavedReportPreviewModeAtom,
} from "app/state/recoil/atoms";

export function ReportPreviewView() {
const { page } = useParams<{ page: string }>();
const [persistedReportState, __] = useRecoilState(persistedReportStateAtom);
const [reportPreviewMode] = useRecoilState(unSavedReportPreviewModeAtom);
const { ref, width } = useResizeObserver<HTMLDivElement>();

const persistedReportState = useRecoilState(persistedReportStateAtom)[0];
const reportPreviewMode = useRecoilState(unSavedReportPreviewModeAtom)[0];

const setReportContentWidths = useRecoilState(reportContentWidthsAtom)[1];
const setReportContentHeights = useRecoilState(reportContentHeightsAtom)[1];

const [containerWidth, setContainerWidth] = useRecoilState(
reportContentContainerWidth
);

const reportData = useStoreState(
(state) => (state.reports.ReportGet.crudData ?? emptyReport) as ReportModel
);
Expand All @@ -50,6 +58,12 @@ export function ReportPreviewView() {
fetchReportData({ getId: page });
}, [page]);

React.useEffect(() => {
if (width && width !== containerWidth) {
setContainerWidth(width);
}
}, [width]);

React.useEffect(() => {
if (!reportPreviewMode) {
setReportPreviewData(reportData);
Expand Down Expand Up @@ -111,7 +125,7 @@ export function ReportPreviewView() {
}}
setHeaderDetails={() => {}}
/>
<Container id="content-container" maxWidth="lg">
<Container id="content-container" maxWidth="lg" ref={ref}>
<Box height={45} />
{reportPreviewData.rows.map((rowFrame, index) => {
if (
Expand Down

0 comments on commit 325a153

Please sign in to comment.