feat(SW-1111) Added Suspense on map

This commit is contained in:
Pontus Dreij
2024-12-09 11:05:44 +01:00
parent c610b4f532
commit b14a1a7097
9 changed files with 190 additions and 60 deletions

View File

@@ -21,6 +21,38 @@ export function MapContainer({ children }: { children: React.ReactNode }) {
setMapTop(`${topPosition + scrollY}px`)
}, [])
useEffect(() => {
const originalOverflowY = document.body.style.overflowY
// Function to enforce overflowY to hidden
const enforceOverflowHidden = () => {
if (document.body.style.overflowY !== "hidden") {
document.body.style.overflowY = "hidden"
}
}
// Set overflowY to hidden initially
enforceOverflowHidden()
// Create a MutationObserver to watch for changes to the style attribute
const observer = new MutationObserver(() => {
enforceOverflowHidden()
})
// Observe changes to the style attribute of the body
observer.observe(document.body, {
attributes: true,
attributeFilter: ["style"],
})
return () => {
// Disconnect the observer on cleanup
observer.disconnect()
// Restore the original overflowY style
document.body.style.overflowY = originalOverflowY
}
}, [])
// Making sure the map is always opened at the top of the page,
// just below the header and booking widget as these should stay visible.
// When closing, the page should scroll back to the position it was before opening the map.