Skip to content

Commit 93848bb

Browse files
committed
fix: request passed from url
1 parent fe93536 commit 93848bb

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/containers/Inspector.tsx

+24-4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,15 @@ const Inspector: React.FC<IProps> = (props) => {
9292
setTabUrl,
9393
handleLabelChange,
9494
setTabResults,
95-
} = useTabs();
95+
} = useTabs(
96+
[
97+
{
98+
name: "New Tab",
99+
content: props.request || { ...emptyJSONRPC },
100+
url: props.url || "",
101+
}
102+
]
103+
);
96104
const [id, incrementId] = useCounter(0);
97105
const [openrpcDocument, setOpenRpcDocument] = useState();
98106
const [json, setJson] = useState(props.request || {
@@ -105,7 +113,7 @@ const Inspector: React.FC<IProps> = (props) => {
105113
const [results, setResults] = useState();
106114
const [url, setUrl] = useState(props.url || "");
107115
const [debouncedUrl] = useDebounce(url, 1000);
108-
const [client, error] = useClient(url);
116+
const [client, error] = useClient(debouncedUrl);
109117
useEffect(() => {
110118
if (props.openrpcMethodObject) {
111119
setJson({
@@ -189,11 +197,15 @@ const Inspector: React.FC<IProps> = (props) => {
189197
}
190198
}
191199
};
200+
useEffect(() => {
201+
refreshOpenRpcDocument();
202+
// eslint-disable-next-line react-hooks/exhaustive-deps
203+
}, [client]);
192204

193205
useEffect(() => {
194206
refreshOpenRpcDocument();
195207
// eslint-disable-next-line react-hooks/exhaustive-deps
196-
}, [debouncedUrl]);
208+
}, [debouncedUrl, tabIndex]);
197209

198210
useEffect(() => {
199211
if (tabs[tabIndex]) {
@@ -249,7 +261,15 @@ const Inspector: React.FC<IProps> = (props) => {
249261
}></Tab>
250262
))}
251263
<Tab disableRipple style={{ minWidth: "50px" }} label={
252-
<IconButton onClick={() => setTabs([...tabs, { name: "New Tab", content: { ...emptyJSONRPC }, url: "" }])}>
264+
<IconButton onClick={() => setTabs([
265+
...tabs,
266+
{
267+
name: "New Tab",
268+
content: { ...emptyJSONRPC },
269+
url: "",
270+
},
271+
],
272+
)}>
253273
<PlusIcon scale={0.5} />
254274
</IconButton>
255275
}>

src/hooks/useQueryParams.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ const useQueryParams = (depth?: number) => {
77
ignoreQueryPrefix: true,
88
depth: depth || 100,
99
decoder(str) {
10-
if (/^(\d+|\d*\.\d+)$/.test(str)) {
11-
return parseFloat(str);
12-
}
10+
if (/^([+-]?[0-9]\d*|0)$/.test(str)) {
11+
return parseInt(str, 10);
12+
}
13+
// if (/^(\d+|\d*\.\d+)$/.test(str)) {
14+
// return parseFloat(str);
15+
// }
1316
if (str === "false") {
1417
return false;
1518
}

src/hooks/useTabs.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ const emptyJSONRPC = {
1717
id: "0",
1818
};
1919

20-
const useTabs = () => {
20+
const useTabs = (defaultTabs?: ITab[]) => {
2121
const [tabIndex, setTabIndex] = useState(0);
22-
const [tabs, setTabs]: [ITab[], Dispatch<any>] = useState([{name: "New Tab", content: emptyJSONRPC, url: undefined}]);
22+
const [tabs, setTabs]: [ITab[], Dispatch<any>] = useState(
23+
defaultTabs || [{ name: "New Tab", content: emptyJSONRPC, url: undefined }],
24+
);
2325

2426
const handleClose = (event: React.MouseEvent<{}>, index: number) => {
2527
if (tabs.length === 1) {

0 commit comments

Comments
 (0)