From f3f2b67abc45bd75292caba6ee3879ea0f8ef255 Mon Sep 17 00:00:00 2001 From: Adam Antal Date: Wed, 4 Dec 2024 17:22:00 +0100 Subject: [PATCH] Initialize slider value based on material type in URL on work page --- components/pages/workPageLayout/WorkPageHeader.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/pages/workPageLayout/WorkPageHeader.tsx b/components/pages/workPageLayout/WorkPageHeader.tsx index 6019ac7..8f2c2d8 100644 --- a/components/pages/workPageLayout/WorkPageHeader.tsx +++ b/components/pages/workPageLayout/WorkPageHeader.tsx @@ -71,6 +71,14 @@ const WorkPageHeader = ({ work }: WorkPageHeaderProps) => { undefined ) const findInitialSliderValue = () => { + const searchParams = new URLSearchParams(window.location.search) + // If we have a material type specified in the URL, we use that + if ( + searchParams.has("type") && + slideSelectOptions.some(option => option.render === searchParams.get("type")) + ) { + return slideSelectOptions.find(option => option.render === searchParams.get("type")) + } return slideSelectOptions.find(option => { return selectedManifestation?.materialTypes.find(materialType => { return materialType.materialTypeGeneral.code.includes(option.value)