fix(BOOK-152): Removed old header references inside useStickyPosition hook to fix offset issue for the sitewide alert
Approved-by: Matilda Landström
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useCallback, useEffect, useState } from "react"
|
import { useCallback, useEffect } from "react"
|
||||||
|
|
||||||
import useStickyPositionStore, {
|
import useStickyPositionStore, {
|
||||||
type StickyElement,
|
type StickyElement,
|
||||||
@@ -43,15 +43,7 @@ export default function useStickyPosition({
|
|||||||
updateHeights,
|
updateHeights,
|
||||||
getAllElements,
|
getAllElements,
|
||||||
} = useStickyPositionStore()
|
} = useStickyPositionStore()
|
||||||
|
const baseTopOffset = 0
|
||||||
/* Used for Current mobile header since that doesn't use this hook.
|
|
||||||
*
|
|
||||||
* Instead, calculate if the mobile header is shown and add the height of
|
|
||||||
* that "manually" to all offsets using this hook.
|
|
||||||
*
|
|
||||||
* TODO: Remove this and just use 0 when the current header has been removed.
|
|
||||||
*/
|
|
||||||
const [baseTopOffset, setBaseTopOffset] = useState(0)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (ref && name) {
|
if (ref && name) {
|
||||||
@@ -119,13 +111,6 @@ export default function useStickyPosition({
|
|||||||
if (!resizeObserver) {
|
if (!resizeObserver) {
|
||||||
const debouncedResizeHandler = debounce(() => {
|
const debouncedResizeHandler = debounce(() => {
|
||||||
updateHeights()
|
updateHeights()
|
||||||
|
|
||||||
// Only do this special handling if we have the current header
|
|
||||||
if (document.body.clientWidth > 950) {
|
|
||||||
setBaseTopOffset(0)
|
|
||||||
} else {
|
|
||||||
setBaseTopOffset(52.41) // The height of current mobile header
|
|
||||||
}
|
|
||||||
}, 100)
|
}, 100)
|
||||||
|
|
||||||
resizeObserver = new ResizeObserver(debouncedResizeHandler)
|
resizeObserver = new ResizeObserver(debouncedResizeHandler)
|
||||||
|
|||||||
Reference in New Issue
Block a user