fix(SW-1960): Changes to how we handle hash inside hotelpages after Next15 upgrade
Approved-by: Michael Zetterberg Approved-by: Linus Flood
This commit is contained in:
@@ -3,13 +3,19 @@
|
|||||||
import { cx } from "class-variance-authority"
|
import { cx } from "class-variance-authority"
|
||||||
import NextLink from "next/link"
|
import NextLink from "next/link"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from "react"
|
import {
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useLayoutEffect,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from "react"
|
||||||
|
|
||||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||||
|
|
||||||
import { StickyElementNameEnum } from "@/stores/sticky-position"
|
import { StickyElementNameEnum } from "@/stores/sticky-position"
|
||||||
|
|
||||||
import useHash from "@/hooks/useHash"
|
|
||||||
import useScrollShadows from "@/hooks/useScrollShadows"
|
import useScrollShadows from "@/hooks/useScrollShadows"
|
||||||
import useScrollSpy from "@/hooks/useScrollSpy"
|
import useScrollSpy from "@/hooks/useScrollSpy"
|
||||||
import useStickyPosition from "@/hooks/useStickyPosition"
|
import useStickyPosition from "@/hooks/useStickyPosition"
|
||||||
@@ -25,7 +31,7 @@ interface TabNavigationProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function TabNavigation({ pageSections }: TabNavigationProps) {
|
export default function TabNavigation({ pageSections }: TabNavigationProps) {
|
||||||
const activeHash = useHash()
|
const [activeHash, setActiveHash] = useState<string>()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const tabNavigationRef = useRef<HTMLDivElement>(null)
|
const tabNavigationRef = useRef<HTMLDivElement>(null)
|
||||||
const tabRefs = useMemo(() => new Map<string, HTMLAnchorElement>(), [])
|
const tabRefs = useMemo(() => new Map<string, HTMLAnchorElement>(), [])
|
||||||
@@ -80,6 +86,7 @@ export default function TabNavigation({ pageSections }: TabNavigationProps) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (activeSectionId) {
|
if (activeSectionId) {
|
||||||
router.replace(`#${activeSectionId}`, { scroll: false })
|
router.replace(`#${activeSectionId}`, { scroll: false })
|
||||||
|
setActiveHash(activeSectionId)
|
||||||
}
|
}
|
||||||
}, [activeSectionId, router])
|
}, [activeSectionId, router])
|
||||||
|
|
||||||
@@ -117,6 +124,7 @@ export default function TabNavigation({ pageSections }: TabNavigationProps) {
|
|||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
pauseScrollSpy()
|
pauseScrollSpy()
|
||||||
|
setActiveHash(hash)
|
||||||
trackHotelTabClick(heading)
|
trackHotelTabClick(heading)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
"use client"
|
|
||||||
|
|
||||||
import { useParams } from "next/navigation"
|
|
||||||
import { useEffect, useState } from "react"
|
|
||||||
|
|
||||||
export default function useHash() {
|
|
||||||
const [hash, setHash] = useState<string | undefined>(undefined)
|
|
||||||
const params = useParams()
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setHash(window.location.hash)
|
|
||||||
}, [params])
|
|
||||||
|
|
||||||
return hash?.slice(1)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user