Skip to content

possible fix for occluded height #449

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

Merged
merged 2 commits into from
May 20, 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
4 changes: 2 additions & 2 deletions public/app.js

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions public/tests/fixed-header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="description" content="React JS recovery meeting finder demo" />
<link rel="icon" type="image/png" href="/logo.png" />
<title>Meetings</title>
</head>
<style type="text/css">
:root {
--header-height: 260px;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
padding-top: var(--header-height);
font-family: Arial, Helvetica, sans-serif;
}
header {
align-items: center;
background-color: darkcyan;
color: white;
display: flex;
height: var(--header-height);
justify-content: center;
padding: 1rem;
position: fixed;
top: 0;
width: 100%;
z-index: 1000;
}
main,
footer {
max-width: 1200px;
margin: 0 auto;
}
footer {
border-top: 1px solid lightslategray;
color: lightslategray;
padding: 2rem;
display: flex;
justify-content: center;
}
</style>
<body>
<header>
<h1>Intergroup Name</h1>
</header>
<main>
<div
id="tsml-ui"
data-src="https://docs.google.com/spreadsheets/d/12Ga8uwMG4WJ8pZ_SEU7vNETp_aQZ-2yNVsYDFqIwHyE/edit?gid=0#gid=0"
data-google="AIzaSyCS9M8Dqk5cMFqA7xvUrQEzT1u5IvcbT7c"
data-timezone="America/Los_Angeles"
></div>
</main>
<footer>&copy; copyright XXXX all rights reserved</footer>
<script>
var tsml_react_config = {
map: {
tiles: {
attribution: `Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>`,
url: 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token=pk.eyJ1Ijoiam9zaHJlaXNuZXIiLCJhIjoiY2tvYXA0YnZxMGRldDJxbzdta25uNGphdiJ9.eay-UKgIT99ALmdw08xBPw',
},
tiles_dark: {
attribution: `Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>`,
url: 'https://api.mapbox.com/styles/v1/mapbox/dark-v10/tiles/{z}/{x}/{y}?access_token=pk.eyJ1Ijoiam9zaHJlaXNuZXIiLCJhIjoiY2tvYXA0YnZxMGRldDJxbzdta25uNGphdiJ9.eay-UKgIT99ALmdw08xBPw',
},
},
};
</script>
<script src="/app.js" async></script>
</body>
</html>
96 changes: 64 additions & 32 deletions src/components/TsmlUI.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useState } from 'react';
import { useEffect, useMemo, useRef, useState } from 'react';

import { Global } from '@emotion/react';
import { useSearchParams } from 'react-router-dom';
Expand Down Expand Up @@ -28,6 +28,7 @@ export default function TsmlUI({
src?: string;
timezone?: string;
}) {
const [occludedHeight, setOccludedHeight] = useState(0);
const { settings, strings } = mergeSettings(userSettings);
const [searchParams] = useSearchParams();
const [state, setState] = useState<State>({
Expand Down Expand Up @@ -219,13 +220,42 @@ export default function TsmlUI({
}
}

// measure area covered up by fixed elements
window.addEventListener('resize', debouncedGetOccludedHeight);
window.addEventListener('scroll', debouncedGetOccludedHeight);
getOccludedHeight();

// manage classes
document.body.classList.add('tsml-ui');
return () => {
window.removeEventListener('resize', debouncedGetOccludedHeight);
window.removeEventListener('scroll', debouncedGetOccludedHeight);
document.body.classList.remove('tsml-ui');
};
}, []);

const getOccludedHeight = () => {
const elements = document.body.getElementsByTagName('*');
let occludedHeight = 0;
for (const element of elements) {
const style = window.getComputedStyle(element);
if (
style.position === 'fixed' &&
parseFloat(style.width) === window.innerWidth
) {
occludedHeight += parseFloat(style.height);
}
}
setOccludedHeight(occludedHeight);
};

const timeoutId = useRef<ReturnType<typeof setTimeout>>();

const debouncedGetOccludedHeight = () => {
clearTimeout(timeoutId.current);
timeoutId.current = setTimeout(getOccludedHeight, 250);
};

// filter data
const [filteredSlugs, inProgress] = useMemo(
() => filterMeetingData(state, setState, settings, strings),
Expand All @@ -241,40 +271,42 @@ export default function TsmlUI({
}

return (
<SettingsContext.Provider value={{ settings, strings }}>
<Global styles={globalCss} />
{state.loading ? (
<Loading />
) : state.input.meeting && state.input.meeting in state.meetings ? (
<Meeting setState={setState} state={state} />
) : (
<>
{settings.show.title && <Title state={state} />}
{settings.show.controls && (
<Controls state={state} setState={setState} />
)}
{(state.alert || state.error) && <Alert state={state} />}
{state.filtering ? (
<Loading />
) : state.input.view === 'table' ? (
<Table
filteredSlugs={filteredSlugs}
inProgress={inProgress}
setState={setState}
state={state}
/>
) : (
<div style={{ display: 'flex', flexGrow: 1 }}>
<Map
<div style={{ minHeight: `calc(100dvh - ${occludedHeight}px)` }}>
<SettingsContext.Provider value={{ settings, strings }}>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the diff looks a little weird below - the only change here is wrapping everything in this div ☝️

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, works on my machine

<Global styles={globalCss} />
{state.loading ? (
<Loading />
) : state.input.meeting && state.input.meeting in state.meetings ? (
<Meeting setState={setState} state={state} />
) : (
<>
{settings.show.title && <Title state={state} />}
{settings.show.controls && (
<Controls state={state} setState={setState} />
)}
{(state.alert || state.error) && <Alert state={state} />}
{state.filtering ? (
<Loading />
) : state.input.view === 'table' ? (
<Table
filteredSlugs={filteredSlugs}
listMeetingsInPopup={true}
inProgress={inProgress}
setState={setState}
state={state}
/>
</div>
)}
</>
)}
</SettingsContext.Provider>
) : (
<div style={{ display: 'flex', flexGrow: 1 }}>
<Map
filteredSlugs={filteredSlugs}
listMeetingsInPopup={true}
setState={setState}
state={state}
/>
</div>
)}
</>
)}
</SettingsContext.Provider>
</div>
);
}
4 changes: 2 additions & 2 deletions src/styles/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const globalCss = css`
--text: #212529;
}

#tsml-ui {
#tsml-ui > div {
background-color: var(--background);
box-sizing: border-box;
color: var(--text);
Expand All @@ -30,8 +30,8 @@ export const globalCss = css`
font-family: var(--font-family);
font-size: var(--font-size);
line-height: 1.5;
min-height: 100dvh;
padding: ${size.gutter}px;
transition: min-height 0.5s;
width: 100%;

* {
Expand Down
Loading