Skip to content

Commit

Permalink
fix(docs): default to first server if exists for inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas committed Jul 21, 2020
1 parent 5d1fe22 commit b6b1fe9
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions templates/docs/gatsby/src/pages/api-documentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const $RefParser = require("json-schema-ref-parser"); //tslint:disable-line
import { useTheme } from "@material-ui/core/styles";
import useInspectorActionStore from "../stores/inspectorActionStore";
import "monaco-editor/esm/vs/language/json/json.worker.js";
import { OpenrpcDocument } from "@open-rpc/meta-schema";

const ApiDocumentation: React.FC = () => {
if (typeof window === "undefined") {
Expand Down Expand Up @@ -59,14 +60,21 @@ const ApiDocumentation: React.FC = () => {
}
}
`);
const [openrpcDocument, setOpenrpcDocument] = useState();
const [openrpcDocument, setOpenrpcDocument] = useState<OpenrpcDocument>();
const [inspectorUrl, setInspectorUrl] = useState<string>();

useEffect(() => {
if (openrpcQueryData.openrpcDocument) {
$RefParser.dereference(JSON.parse(openrpcQueryData.openrpcDocument.openrpcDocument)).then(setOpenrpcDocument);
}
}, [openrpcQueryData]);

useEffect(() => {
if (openrpcDocument && openrpcDocument.servers && openrpcDocument.servers[0]) {
setInspectorUrl(openrpcDocument.servers[0].url);
}
}, [openrpcDocument])

return (
<PlaygroundSplitPane
direction="horizontal"
Expand All @@ -83,14 +91,13 @@ const ApiDocumentation: React.FC = () => {
height: "100%",
}}
right={
openrpcDocument ?
<Inspector
hideToggleTheme={true}
openrpcDocument={openrpcDocument}
darkMode={darkmode.value}
request={inspectorContents && inspectorContents.request}
/>
: null
<Inspector
url={inspectorUrl}
hideToggleTheme={true}
openrpcDocument={openrpcDocument}
darkMode={darkmode.value}
request={inspectorContents && inspectorContents.request}
/>
}
left={
<>
Expand Down

0 comments on commit b6b1fe9

Please sign in to comment.