Skip to content

Commit 42cb23e

Browse files
authored
Merge pull request #823 from kleros/fix(web)/any-types
fix(web): add MouseEvent & IPolicy types
2 parents 7370276 + a9acd6b commit 42cb23e

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

web/src/hooks/useFocusOutside.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import React, { useEffect } from "react";
22

3-
export function useFocusOutside(
4-
ref: React.RefObject<HTMLDivElement>,
5-
callback: () => void
6-
) {
3+
export function useFocusOutside(ref: React.RefObject<HTMLDivElement>, callback: () => void) {
74
useEffect(() => {
8-
function handleEvent(event: any) {
9-
if (ref.current && !ref.current.contains(event.target)) {
5+
function handleEvent(event: FocusEvent | MouseEvent) {
6+
if (ref.current && !ref.current.contains(event.target as Node)) {
107
callback();
118
}
129
}

web/src/pages/Courts/CourtDetails/Description.tsx

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
import React, { useEffect, useState } from "react";
22
import styled from "styled-components";
33
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";
125
import { Tabs } from "@kleros/ui-components-library";
136
import { useCourtPolicy } from "queries/useCourtPolicy";
147

8+
interface IPolicy {
9+
description?: string;
10+
requiredSkills?: string;
11+
summary?: string;
12+
}
13+
1514
const TABS = [
1615
{
1716
text: "Purpose",
1817
value: 0,
1918
path: "purpose",
20-
isVisible: (policy: any) => !!policy?.description,
19+
isVisible: (policy: IPolicy) => !!policy?.description,
2120
},
2221
{
2322
text: "Skills",
2423
value: 1,
2524
path: "skills",
26-
isVisible: (policy: any) => !!policy?.requiredSkills,
25+
isVisible: (policy: IPolicy) => !!policy?.requiredSkills,
2726
},
2827
{
2928
text: "Policy",
3029
value: 2,
3130
path: "policy",
32-
isVisible: (policy: any) => !!policy?.summary,
31+
isVisible: (policy: IPolicy) => !!policy?.summary,
3332
},
3433
];
3534

@@ -38,13 +37,8 @@ const Description: React.FC = () => {
3837
const { data: policy } = useCourtPolicy(id);
3938
const navigate = useNavigate();
4039
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]);
4842

4943
const filteredTabs = TABS.filter(({ isVisible }) => isVisible(policy));
5044

@@ -72,11 +66,7 @@ const Description: React.FC = () => {
7266

7367
const formatMarkdown = (markdown?: string) =>
7468
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>
8070
) : (
8171
<p>Loading...</p>
8272
);

0 commit comments

Comments
 (0)