1
1
import React , { useEffect , useState } from "react" ;
2
2
import styled from "styled-components" ;
3
3
import ReactMarkdown from "react-markdown" ;
4
- import {
5
- Routes ,
6
- Route ,
7
- Navigate ,
8
- useParams ,
9
- useNavigate ,
10
- useLocation ,
11
- } from "react-router-dom" ;
4
+ import { Routes , Route , Navigate , useParams , useNavigate , useLocation } from "react-router-dom" ;
12
5
import { Tabs } from "@kleros/ui-components-library" ;
13
6
import { useCourtPolicy } from "queries/useCourtPolicy" ;
14
7
8
+ interface IPolicy {
9
+ description ?: string ;
10
+ requiredSkills ?: string ;
11
+ summary ?: string ;
12
+ }
13
+
15
14
const TABS = [
16
15
{
17
16
text : "Purpose" ,
18
17
value : 0 ,
19
18
path : "purpose" ,
20
- isVisible : ( policy : any ) => ! ! policy ?. description ,
19
+ isVisible : ( policy : IPolicy ) => ! ! policy ?. description ,
21
20
} ,
22
21
{
23
22
text : "Skills" ,
24
23
value : 1 ,
25
24
path : "skills" ,
26
- isVisible : ( policy : any ) => ! ! policy ?. requiredSkills ,
25
+ isVisible : ( policy : IPolicy ) => ! ! policy ?. requiredSkills ,
27
26
} ,
28
27
{
29
28
text : "Policy" ,
30
29
value : 2 ,
31
30
path : "policy" ,
32
- isVisible : ( policy : any ) => ! ! policy ?. summary ,
31
+ isVisible : ( policy : IPolicy ) => ! ! policy ?. summary ,
33
32
} ,
34
33
] ;
35
34
@@ -38,13 +37,8 @@ const Description: React.FC = () => {
38
37
const { data : policy } = useCourtPolicy ( id ) ;
39
38
const navigate = useNavigate ( ) ;
40
39
const currentPathName = useLocation ( ) . pathname . split ( "/" ) . at ( - 1 ) ;
41
- const [ currentTab , setCurrentTab ] = useState (
42
- TABS . findIndex ( ( { path } ) => path === currentPathName )
43
- ) ;
44
- useEffect (
45
- ( ) => setCurrentTab ( TABS . findIndex ( ( { path } ) => path === currentPathName ) ) ,
46
- [ currentPathName ]
47
- ) ;
40
+ const [ currentTab , setCurrentTab ] = useState ( TABS . findIndex ( ( { path } ) => path === currentPathName ) ) ;
41
+ useEffect ( ( ) => setCurrentTab ( TABS . findIndex ( ( { path } ) => path === currentPathName ) ) , [ currentPathName ] ) ;
48
42
49
43
const filteredTabs = TABS . filter ( ( { isVisible } ) => isVisible ( policy ) ) ;
50
44
@@ -72,11 +66,7 @@ const Description: React.FC = () => {
72
66
73
67
const formatMarkdown = ( markdown ?: string ) =>
74
68
markdown ? (
75
- < ReactMarkdown >
76
- { typeof markdown === "string"
77
- ? markdown . replace ( / \n / g, " \n" )
78
- : markdown }
79
- </ ReactMarkdown >
69
+ < ReactMarkdown > { typeof markdown === "string" ? markdown . replace ( / \n / g, " \n" ) : markdown } </ ReactMarkdown >
80
70
) : (
81
71
< p > Loading...</ p >
82
72
) ;
0 commit comments