feat(SW-1347): SidePeekProvider is now using '#s-' instead of '?s='
This commit is contained in:
@@ -43,7 +43,7 @@ export default async function AmenitiesList({
|
|||||||
</div>
|
</div>
|
||||||
<Link
|
<Link
|
||||||
scroll={false}
|
scroll={false}
|
||||||
href={`?s=${amenities[lang]}`}
|
href={`#s-${amenities[lang]}`}
|
||||||
color="burgundy"
|
color="burgundy"
|
||||||
variant="icon"
|
variant="icon"
|
||||||
className={styles.showAllAmenities}
|
className={styles.showAllAmenities}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export default function ActivitiesCardGrid(activitiesCard: ActivityCard) {
|
|||||||
theme: hasImage ? "image" : "primaryDark",
|
theme: hasImage ? "image" : "primaryDark",
|
||||||
primaryButton: hasImage
|
primaryButton: hasImage
|
||||||
? {
|
? {
|
||||||
href: `?s=${activities[lang]}`,
|
href: `#s-${activities[lang]}`,
|
||||||
title: activitiesCard.ctaText,
|
title: activitiesCard.ctaText,
|
||||||
isExternal: false,
|
isExternal: false,
|
||||||
scrollOnClick: false,
|
scrollOnClick: false,
|
||||||
@@ -29,7 +29,7 @@ export default function ActivitiesCardGrid(activitiesCard: ActivityCard) {
|
|||||||
secondaryButton: hasImage
|
secondaryButton: hasImage
|
||||||
? undefined
|
? undefined
|
||||||
: {
|
: {
|
||||||
href: `?s=${activities[lang]}`,
|
href: `#s-${activities[lang]}`,
|
||||||
title: activitiesCard.ctaText,
|
title: activitiesCard.ctaText,
|
||||||
isExternal: false,
|
isExternal: false,
|
||||||
scrollOnClick: false,
|
scrollOnClick: false,
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export default async function IntroSection({
|
|||||||
className={styles.introLink}
|
className={styles.introLink}
|
||||||
color="burgundy"
|
color="burgundy"
|
||||||
variant="icon"
|
variant="icon"
|
||||||
href={`?s=${about[lang]}`}
|
href={`#s-${about[lang]}`}
|
||||||
scroll={false}
|
scroll={false}
|
||||||
>
|
>
|
||||||
{intl.formatMessage({ id: "Read more about the hotel" })}
|
{intl.formatMessage({ id: "Read more about the hotel" })}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export function RoomCard({ room }: RoomCardProps) {
|
|||||||
</Body>
|
</Body>
|
||||||
</div>
|
</div>
|
||||||
<Button intent="text" type="button" size="medium" theme="base" asChild>
|
<Button intent="text" type="button" size="medium" theme="base" asChild>
|
||||||
<Link scroll={false} href={`?s=${getRoomNameAsParam(name)}`}>
|
<Link scroll={false} href={`#s-${getRoomNameAsParam(name)}`}>
|
||||||
{intl.formatMessage({ id: "See room details" })}
|
{intl.formatMessage({ id: "See room details" })}
|
||||||
<ChevronRightSmallIcon color="burgundy" width={20} height={20} />
|
<ChevronRightSmallIcon color="burgundy" width={20} height={20} />
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { createContext, useEffect, useState } from "react"
|
import { createContext, useEffect, useState } from "react"
|
||||||
|
|
||||||
|
import useHash from "@/hooks/useHash"
|
||||||
|
|
||||||
interface ISidePeekContext {
|
interface ISidePeekContext {
|
||||||
handleClose: (isOpen: boolean) => void
|
handleClose: (isOpen: boolean) => void
|
||||||
activeSidePeek: string | null
|
activeSidePeek: string | null
|
||||||
@@ -9,28 +11,24 @@ interface ISidePeekContext {
|
|||||||
|
|
||||||
export const SidePeekContext = createContext<ISidePeekContext | null>(null)
|
export const SidePeekContext = createContext<ISidePeekContext | null>(null)
|
||||||
|
|
||||||
function SidePeekProvider({ children }: React.PropsWithChildren) {
|
export default function SidePeekProvider({
|
||||||
|
children,
|
||||||
|
}: React.PropsWithChildren) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const pathname = usePathname()
|
const hash = useHash()
|
||||||
const searchParams = useSearchParams()
|
const [activeSidePeek, setActiveSidePeek] = useState<string | null>(null)
|
||||||
const [activeSidePeek, setActiveSidePeek] = useState<string | null>(() => {
|
|
||||||
const sidePeekParam = searchParams.get("s")
|
|
||||||
return sidePeekParam || null
|
|
||||||
})
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const sidePeekParam = searchParams.get("s")
|
if (hash?.startsWith("s-")) {
|
||||||
if (sidePeekParam !== activeSidePeek) {
|
setActiveSidePeek(hash.slice(2))
|
||||||
setActiveSidePeek(sidePeekParam)
|
} else {
|
||||||
|
setActiveSidePeek(null)
|
||||||
}
|
}
|
||||||
}, [searchParams, activeSidePeek])
|
}, [hash, setActiveSidePeek])
|
||||||
|
|
||||||
function handleClose(isOpen: boolean) {
|
function handleClose(isOpen: boolean) {
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
const nextSearchParams = new URLSearchParams(searchParams.toString())
|
router.push(window.location.pathname, { scroll: false })
|
||||||
nextSearchParams.delete("s")
|
|
||||||
|
|
||||||
router.push(`${pathname}?${nextSearchParams}`, { scroll: false })
|
|
||||||
setActiveSidePeek(null)
|
setActiveSidePeek(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,5 +39,3 @@ function SidePeekProvider({ children }: React.PropsWithChildren) {
|
|||||||
</SidePeekContext.Provider>
|
</SidePeekContext.Provider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SidePeekProvider
|
|
||||||
|
|||||||
@@ -8,21 +8,8 @@ export default function useHash() {
|
|||||||
const params = useParams()
|
const params = useParams()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const updateHash = () => {
|
setHash(window.location.hash)
|
||||||
const newHash = window.location.hash
|
|
||||||
? window.location.hash.slice(1)
|
|
||||||
: undefined
|
|
||||||
setHash(newHash)
|
|
||||||
}
|
|
||||||
|
|
||||||
updateHash()
|
|
||||||
|
|
||||||
window.addEventListener("hashchange", updateHash)
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener("hashchange", updateHash)
|
|
||||||
}
|
|
||||||
}, [params])
|
}, [params])
|
||||||
|
|
||||||
return hash
|
return hash?.slice(1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ function setCardProps(
|
|||||||
heading,
|
heading,
|
||||||
scriptedTopTitle,
|
scriptedTopTitle,
|
||||||
secondaryButton: {
|
secondaryButton: {
|
||||||
href: `?s=${href}`,
|
href: `#s-${href}`,
|
||||||
title: buttonText,
|
title: buttonText,
|
||||||
isExternal: false,
|
isExternal: false,
|
||||||
scrollOnClick: false,
|
scrollOnClick: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user