Skip to content

Commit

Permalink
fix: request passed from url
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas committed Mar 6, 2020
1 parent fe93536 commit 93848bb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
28 changes: 24 additions & 4 deletions src/containers/Inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@ const Inspector: React.FC<IProps> = (props) => {
setTabUrl,
handleLabelChange,
setTabResults,
} = useTabs();
} = useTabs(
[
{
name: "New Tab",
content: props.request || { ...emptyJSONRPC },
url: props.url || "",
}
]
);
const [id, incrementId] = useCounter(0);
const [openrpcDocument, setOpenRpcDocument] = useState();
const [json, setJson] = useState(props.request || {
Expand All @@ -105,7 +113,7 @@ const Inspector: React.FC<IProps> = (props) => {
const [results, setResults] = useState();
const [url, setUrl] = useState(props.url || "");
const [debouncedUrl] = useDebounce(url, 1000);
const [client, error] = useClient(url);
const [client, error] = useClient(debouncedUrl);
useEffect(() => {
if (props.openrpcMethodObject) {
setJson({
Expand Down Expand Up @@ -189,11 +197,15 @@ const Inspector: React.FC<IProps> = (props) => {
}
}
};
useEffect(() => {
refreshOpenRpcDocument();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [client]);

useEffect(() => {
refreshOpenRpcDocument();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [debouncedUrl]);
}, [debouncedUrl, tabIndex]);

useEffect(() => {
if (tabs[tabIndex]) {
Expand Down Expand Up @@ -249,7 +261,15 @@ const Inspector: React.FC<IProps> = (props) => {
}></Tab>
))}
<Tab disableRipple style={{ minWidth: "50px" }} label={
<IconButton onClick={() => setTabs([...tabs, { name: "New Tab", content: { ...emptyJSONRPC }, url: "" }])}>
<IconButton onClick={() => setTabs([
...tabs,
{
name: "New Tab",
content: { ...emptyJSONRPC },
url: "",
},
],
)}>
<PlusIcon scale={0.5} />
</IconButton>
}>
Expand Down
9 changes: 6 additions & 3 deletions src/hooks/useQueryParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ const useQueryParams = (depth?: number) => {
ignoreQueryPrefix: true,
depth: depth || 100,
decoder(str) {
if (/^(\d+|\d*\.\d+)$/.test(str)) {
return parseFloat(str);
}
if (/^([+-]?[0-9]\d*|0)$/.test(str)) {
return parseInt(str, 10);
}
// if (/^(\d+|\d*\.\d+)$/.test(str)) {
// return parseFloat(str);
// }
if (str === "false") {
return false;
}
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/useTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ const emptyJSONRPC = {
id: "0",
};

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

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

0 comments on commit 93848bb

Please sign in to comment.