Skip to content

Commit 2d235ae

Browse files
committed
feat: use old mechanism
1 parent 23353be commit 2d235ae

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

public/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
Learn how to configure a non-root public URL by running `npm run build`.
3030
-->
3131
<title>Code Capsule App</title>
32+
<script>
33+
document.domain = '%REACT_APP_GRAASP_DOMAIN%';
34+
if (window.frameElement) {
35+
window.frameElement.style['min-height'] = '70vh';
36+
}
37+
</script>
3238
</head>
3339
<body>
3440
<noscript>You need to enable JavaScript to run this app.</noscript>

src/components/diffView/DiffView.tsx

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { FC } from 'react';
1+
import { FC, useEffect, useRef, useState } from 'react';
22
import ReactDiffViewer from 'react-diff-viewer';
33

4+
import { useLocalContext } from '@graasp/apps-query-client';
5+
46
import { Stack } from '@mui/material';
57

68
import { DIFF_VIEW_SETTINGS_NAME } from '../../config/appSettingsTypes';
@@ -9,13 +11,57 @@ import { DEFAULT_DIFF_VIEW_SETTINGS } from '../../config/settings';
911
import { DiffViewSettingsKeys } from '../../interfaces/settings';
1012
import { useSettings } from '../context/SettingsContext';
1113

14+
const ADAPT_HEIGHT_TIMEOUT = 50;
15+
1216
const DiffView: FC = () => {
1317
const {
1418
[DIFF_VIEW_SETTINGS_NAME]: diffViewSettings = DEFAULT_DIFF_VIEW_SETTINGS,
1519
} = useSettings();
20+
const context = useLocalContext();
21+
const rootRef = useRef();
22+
const [height, setHeight] = useState(0);
23+
24+
const adaptHeight = (): void => {
25+
// set timeout to leave time for the height to be set
26+
setTimeout(() => {
27+
// adapt height when not in standalone (so when in an iframe)
28+
if (!context?.get('standalone')) {
29+
// get height from the root element and add a small margin
30+
// @ts-ignore
31+
const clientRect = rootRef?.current?.getBoundingClientRect();
32+
if (window.frameElement && clientRect) {
33+
const newHeight = clientRect.height;
34+
if (height !== newHeight) {
35+
setHeight(newHeight);
36+
// @ts-ignore
37+
window.frameElement.style['min-height'] = `${newHeight}px`;
38+
// @ts-ignore
39+
window.frameElement.style.overflowY = 'hidden';
40+
// @ts-ignore
41+
window.frameElement.scrolling = 'no';
42+
// @ts-ignore
43+
window.frameElement.style.height = `${newHeight}px`;
44+
}
45+
}
46+
}
47+
}, ADAPT_HEIGHT_TIMEOUT);
48+
};
49+
50+
useEffect(
51+
() => {
52+
adaptHeight();
53+
},
54+
// eslint-disable-next-line react-hooks/exhaustive-deps
55+
[],
56+
);
1657

1758
return (
18-
<Stack data-cy={DIFF_VIEW_CONTAINER_CY} direction="column" m={2}>
59+
<Stack
60+
data-cy={DIFF_VIEW_CONTAINER_CY}
61+
direction="column"
62+
m={2}
63+
ref={rootRef}
64+
>
1965
<ReactDiffViewer
2066
linesOffset={diffViewSettings[DiffViewSettingsKeys.LinesOffset]}
2167
oldValue={diffViewSettings[DiffViewSettingsKeys.OldCode]}

0 commit comments

Comments
 (0)