Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert back the full page scroll logic + fix infinite scroll updates #45

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions components/iframeCommunication.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useEffect, useRef } from 'react';
import { useRouter } from 'next/router';

const HEIGHT_DIFFERENCE_THRESHOLD = 130; // ~30 locally and 122 on Sandbox (Donna PC)

const allowedOrigins = ['https://alkem.io', 'https://dev-alkem.io', 'https://acc-alkem.io', 'https://sandbox-alkem.io', 'http://localhost:3000'];
const isOriginValid = (origin) => allowedOrigins.includes(origin);

Expand Down Expand Up @@ -40,24 +42,25 @@ const IframeCommunication = () => {

const sendPageHeight = () => {
const pageHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
console.log('Scroll change new/old: ', pageHeight, lastHeight.current);

// Only send if there's a meaningful difference in height
if (Math.abs(pageHeight - lastHeight.current) > 40) {
if (Math.abs(pageHeight - lastHeight.current) > HEIGHT_DIFFERENCE_THRESHOLD) {
lastHeight.current = pageHeight;

// Debounce the message to avoid excessive calls
clearTimeout(debounceTimeout.current);
debounceTimeout.current = setTimeout(() => {
console.log('Scroll change SENT: ', pageHeight, lastHeight.current);
sendMessageToParent({ type: SupportedMessageTypes.PageHeight, height: pageHeight });
}, 50);
}
};


useEffect(() => {
// Send initial page height and path
// Send path
sendMessageToParent({ type: SupportedMessageTypes.PageChange, url: router.pathname });
sendPageHeight();

// Observe changes to the body size
const resizeObserver = new ResizeObserver(sendPageHeight);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alkemio/documentation",
"version": "0.1.0",
"version": "0.1.1",
"description": "Alkemio platform documentation",
"author": "Alkemio Foundation",
"repository": {
Expand Down
11 changes: 5 additions & 6 deletions pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import IframeCommunication from '../components/iframeCommunication';

export default function MyApp({ Component, pageProps }) {
useEffect(() => {
if (typeof window === 'undefined') return;
if (window.self !== window.top) {
document.body.classList.add("in-iframe");
} else {
document.body.classList.remove("in-iframe");
}
try {
if (window.self === window.top) {
document.body.classList.add("not-in-iframe");
}
} catch (e) {}
}, []);

return (
Expand Down
34 changes: 1 addition & 33 deletions styles.css
Original file line number Diff line number Diff line change
@@ -1,43 +1,11 @@
html, body {
height: 100vh;
max-height: 100vh;
overflow: hidden;
}

body {
font-family: 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', 'Helvetica',
'Arial', sans-serif;
overflow-y: hidden;
}

body:not(.in-iframe) {
body.not-in-iframe {
overflow-y: auto;
}

.main-content {
flex: 1;
height: 100%;
max-height: 100vh;
overflow-y: auto; /* Zorgt ervoor dat de inhoud in de iframe kan scrollen */
padding: 20px;
background: white;
}

iframe {
width: 100%;
height: 100vh !important; /* Zorgt dat de iframe altijd de volle hoogte krijgt */
overflow-y: auto !important; /* Voorkomt dat de iframe-inhoud wordt afgesneden */
border: none;
}

body.in-iframe {
overflow-y: auto !important;
height: auto !important;
max-height: 100vh !important;
}

body.in-iframe .main-content {
overflow-y: auto !important;
height: auto !important;
max-height: 100vh !important;
}
Loading