Skip to content

Commit

Permalink
fix: remove counter + fix issue with props.openrpcDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas committed Apr 1, 2020
1 parent cea3da6 commit a78ece9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
30 changes: 9 additions & 21 deletions src/containers/Inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@ interface IProps {
onToggleDarkMode?: () => void;
}

function useCounter(defaultValue: number): [number, () => void] {
const [counter, setCounter] = useState(defaultValue);

const incrementCounter = () => {
setCounter(counter + 1);
};

return [counter, incrementCounter];
}

const emptyJSONRPC = {
jsonrpc: "2.0",
method: "",
Expand All @@ -134,10 +124,11 @@ const Inspector: React.FC<IProps> = (props) => {
name: props.request ? props.request.method : "New Tab",
content: props.request || { ...emptyJSONRPC },
url: props.url || "",
openrpcDocument: props.openrpcDocument,
},
],
);
const [id, incrementId] = useCounter(0);
const id = 0;
const [responseEditor, setResponseEditor] = useState();
useMonacoVimMode(responseEditor);
const [openrpcDocument, setOpenRpcDocument] = useState(props.openrpcDocument);
Expand All @@ -163,6 +154,7 @@ const Inspector: React.FC<IProps> = (props) => {
name: props.request ? props.request.method || "New Tab" : "New Tab",
content: props.request,
url: props.url,
openrpcDocument,
},
]);
setTabIndex(tabs.length);
Expand Down Expand Up @@ -244,7 +236,6 @@ const Inspector: React.FC<IProps> = (props) => {
setResults(convertedError);
setTabResults(tabIndex, convertedError);
}
incrementId();
}
};
function handleResponseEditorDidMount(__: any, editor: any) {
Expand All @@ -266,13 +257,8 @@ const Inspector: React.FC<IProps> = (props) => {
}
};
const refreshOpenRpcDocument = async () => {
if (!transport) {
setOpenRpcDocument(undefined);
setTabOpenRPCDocument(tabIndex, undefined);
return;
}
try {
const d = await transport.sendData({
const d = await transport?.sendData({
internalID: id,
request: {
jsonrpc: "2.0",
Expand All @@ -292,7 +278,9 @@ const Inspector: React.FC<IProps> = (props) => {
}
};
useEffect(() => {
setOpenRpcDocument(undefined);
if (!props.openrpcDocument) {
setOpenRpcDocument(undefined);
}
refreshOpenRpcDocument();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [transport, tabIndex]);
Expand All @@ -308,7 +296,7 @@ const Inspector: React.FC<IProps> = (props) => {

useEffect(() => {
setOpenRpcDocument(props.openrpcDocument);
setTabOpenRPCDocument(tabIndex, undefined);
setTabOpenRPCDocument(tabIndex, props.openrpcDocument);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.openrpcDocument]);

Expand Down Expand Up @@ -426,7 +414,7 @@ const Inspector: React.FC<IProps> = (props) => {
{
name: "New Tab",
content: { ...emptyJSONRPC, id },
openrpcDocument: undefined,
openrpcDocument,
url,
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/containers/JSONRPCRequestEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const JSONRPCRequestEditor: React.FC<IProps> = (props) => {
addDiagnostics(modelUri.toString(), schema, monaco);

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.openrpcDocument]);
}, [props.openrpcDocument, editor]);

function handleEditorDidMount(_: any, ed: any) {
setEditor(ed);
Expand Down

0 comments on commit a78ece9

Please sign in to comment.