@@ -2,8 +2,7 @@ import React, { useEffect } from "react";
22import styled from "styled-components" ;
33
44import ReactMarkdown from "react-markdown" ;
5- import { Routes , Route , Navigate , useParams , useNavigate , useLocation } from "react-router-dom" ;
6-
5+ import { Routes , Route , Navigate , useParams , useNavigate , useLocation , useSearchParams } from "react-router-dom" ;
76import { Tabs } from "@kleros/ui-components-library" ;
87
98import { useCourtPolicy } from "queries/useCourtPolicy" ;
@@ -97,38 +96,34 @@ const Description: React.FC = () => {
9796 const { data : policy } = useCourtPolicy ( id ) ;
9897 const navigate = useNavigate ( ) ;
9998 const location = useLocation ( ) ;
99+ const [ searchParams ] = useSearchParams ( ) ;
100+ const suffix = searchParams . toString ( ) ? `?${ searchParams . toString ( ) } ` : "" ;
100101 const currentPathName = location . pathname . split ( "/" ) . at ( - 1 ) ;
101102
102103 const filteredTabs = TABS . filter ( ( { isVisible } ) => isVisible ( policy ) ) ;
103104 const currentTab = TABS . findIndex ( ( { path } ) => path === currentPathName ) ;
104105
105- const handleTabChange = ( index : number ) => {
106- navigate ( TABS [ index ] . path ) ;
106+ const handleTabChange = ( i : number ) => {
107+ navigate ( ` ${ TABS [ i ] . path } ${ suffix } ` ) ;
107108 } ;
108-
109109 useEffect ( ( ) => {
110110 if ( currentPathName && ! filteredTabs . map ( ( t ) => t . path ) . includes ( currentPathName ) && filteredTabs . length > 0 ) {
111- navigate ( filteredTabs [ 0 ] . path , { replace : true } ) ;
111+ navigate ( ` ${ filteredTabs [ 0 ] . path } ${ suffix } ` , { replace : true } ) ;
112112 }
113- } , [ policy , currentPathName , filteredTabs , navigate ] ) ;
114-
115- return (
116- < >
117- { policy ? (
118- < Container id = "description" >
119- < StyledTabs currentValue = { currentTab } items = { filteredTabs } callback = { handleTabChange } />
120- < TextContainer >
121- < Routes >
122- < Route path = "purpose" element = { formatMarkdown ( policy ?. purpose ) } />
123- < Route path = "skills" element = { formatMarkdown ( policy ?. requiredSkills ) } />
124- < Route path = "policy" element = { formatMarkdown ( policy ?. rules ) } />
125- < Route path = "*" element = { < Navigate to = { filteredTabs . length > 0 ? filteredTabs [ 0 ] . path : "" } replace /> } />
126- </ Routes >
127- </ TextContainer >
128- </ Container >
129- ) : null }
130- </ >
131- ) ;
113+ } , [ policy , currentPathName , filteredTabs , navigate , suffix ] ) ;
114+ return policy ? (
115+ < Container id = "description" >
116+ < StyledTabs currentValue = { currentTab } items = { filteredTabs } callback = { handleTabChange } />
117+ < TextContainer >
118+ < Routes >
119+ < Route path = "purpose" element = { formatMarkdown ( policy ?. purpose ) } />
120+ < Route path = "skills" element = { formatMarkdown ( policy ?. requiredSkills ) } />
121+ < Route path = "policy" element = { formatMarkdown ( policy ?. rules ) } />
122+ < Route path = "*" element = { < Navigate to = { filteredTabs . length > 0 ? filteredTabs [ 0 ] . path : "" } replace /> } />
123+ </ Routes >
124+ </ TextContainer >
125+ </ Container >
126+ ) : null ;
132127} ;
133128
134129const formatMarkdown = ( markdown ?: string ) =>
0 commit comments