Skip to content

Commit

Permalink
Trigger update when container resizes
Browse files Browse the repository at this point in the history
  • Loading branch information
mmuzikar committed May 9, 2023
1 parent 7d14727 commit b13af97
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/module/src/LogViewer/LogViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ const LogViewerBase: React.FunctionComponent<LogViewerProps> = memo(
const [loading, setLoading] = useState(true);
const [listKey, setListKey] = useState(1);

const [, setEmptyState] = useState({});

/* Parse data every time it changes */
const parsedData = React.useMemo(() => parseConsoleOutput(data), [data]);

Expand All @@ -113,13 +115,21 @@ const LogViewerBase: React.FunctionComponent<LogViewerProps> = memo(
let resizeTimer = null as any;

useEffect(() => {
let observer : ResizeObserver | undefined = undefined;
if (containerRef && containerRef.current) {
window.addEventListener('resize', callbackResize);
observer = new ResizeObserver((event) => {
setEmptyState({});
});
observer.observe(containerRef.current);
setLoading(false);
createDummyElements();
ansiUp.resetStyles();
}
return () => window.removeEventListener('resize', callbackResize);
return () => {
window.removeEventListener('resize', callbackResize);
observer?.disconnect();
}
}, [containerRef.current]);

const callbackResize = () => {
Expand Down Expand Up @@ -168,6 +178,9 @@ const LogViewerBase: React.FunctionComponent<LogViewerProps> = memo(
}, [parsedData, scrollToRow]);

const createDummyElements = () => {
if (!(containerRef && containerRef.current)) {
return;
}
// create dummy elements
const dummyIndex = document.createElement('span');
dummyIndex.className = css(styles.logViewerIndex);
Expand Down

0 comments on commit b13af97

Please sign in to comment.