diff --git a/docs/gatsby-config.js b/docs/gatsby-config.js
index 54bb19853..82498dcd1 100644
--- a/docs/gatsby-config.js
+++ b/docs/gatsby-config.js
@@ -33,7 +33,7 @@ module.exports = {
resolve: `gatsby-plugin-mdx`,
options: {
defaultLayouts: {
- default: require.resolve("./src/components/layout.js"),
+ default: require.resolve("./src/components/layout.tsx"),
},
},
},
diff --git a/docs/src/components/layout.js b/docs/src/components/layout.tsx
similarity index 77%
rename from docs/src/components/layout.js
rename to docs/src/components/layout.tsx
index 0359ea629..11b62d6e1 100644
--- a/docs/src/components/layout.js
+++ b/docs/src/components/layout.tsx
@@ -5,11 +5,13 @@
* See: https://www.gatsbyjs.org/docs/use-static-query/
*/
-import React from "react"
+import React, { useState } from "react"
import PropTypes from "prop-types"
import { useStaticQuery, graphql } from "gatsby"
+import JacdacProvider from "../jacdac/Provider"
import Header from "./header"
+// tslint:disable-next-line: no-import-side-effect
import "./layout.css"
const Layout = ({ children }) => {
@@ -22,9 +24,8 @@ const Layout = ({ children }) => {
}
}
`)
-
return (
- <>
+
{
>
{children}
- >
+
)
}
diff --git a/docs/src/jacdac/Component.tsx b/docs/src/jacdac/Component.tsx
new file mode 100644
index 000000000..cfd70794d
--- /dev/null
+++ b/docs/src/jacdac/Component.tsx
@@ -0,0 +1,11 @@
+import React from "react";
+import JacdacContext from "./Context";
+import ConnectButton from "./ConnectButton"
+
+const JacdacComponent = ({ children }) => {
+ return
+ {({ bus }) => bus ? children : }
+
+}
+
+export default JacdacComponent;
\ No newline at end of file
diff --git a/docs/src/jacdac/ConnectButton.tsx b/docs/src/jacdac/ConnectButton.tsx
new file mode 100644
index 000000000..1ae44bea4
--- /dev/null
+++ b/docs/src/jacdac/ConnectButton.tsx
@@ -0,0 +1,11 @@
+import React from "react";
+import { Button } from "gatsby-theme-material-ui";
+import JacdacContext from "./Context";
+
+function ConnectButton() {
+ return
+ {({ bus, connectAsync, disconnectAsync }) => }
+
+}
+
+export default ConnectButton;
\ No newline at end of file
diff --git a/docs/src/jacdac/Provider.tsx b/docs/src/jacdac/Provider.tsx
new file mode 100644
index 000000000..6ed2d8845
--- /dev/null
+++ b/docs/src/jacdac/Provider.tsx
@@ -0,0 +1,22 @@
+import React, { useState } from "react";
+import { Bus } from "../../../src/bus";
+import { requestUSBBus } from "../../../src/hf2";
+import JacdacContext from "./Context";
+import { Helmet } from "react-helmet";
+
+const JacdacProvider = ({ children }) => {
+ const [bus, setBus] = useState(undefined);
+ const connectAsync = () => !bus ? requestUSBBus().then(b => setBus(b)) : Promise.resolve();
+ const disconnectAsync = () => bus ? bus.disconnectAsync() : Promise.resolve();
+ return (
+
+
+
+
+
+ {children}
+
+
+ )
+}
+export default JacdacProvider;
\ No newline at end of file
diff --git a/docs/src/jacdac/context.tsx b/docs/src/jacdac/context.tsx
index 1711dc5c3..1c5490d02 100644
--- a/docs/src/jacdac/context.tsx
+++ b/docs/src/jacdac/context.tsx
@@ -1,18 +1,11 @@
-import React, { useContext } from "react";
-import { Button } from "gatsby-theme-material-ui";
-import { requestUSBBus } from "../../../src/hf2";
+import React from "react";
import { Bus } from "../../../src/bus";
-const JacdacContext = React.createContext({
- bus: undefined,
- connectAsync: () => requestUSBBus()
-});
+const JacdacContext = React.createContext<{
+ bus: Bus,
+ connectAsync: () => Promise,
+ disconnectAsync: () => Promise
+}>({ bus: undefined, connectAsync: undefined, disconnectAsync: undefined });
JacdacContext.displayName = "jacdac";
-export function ConnectButton() {
- return
- {({ bus, connectAsync }) => }
-
-}
-
export default JacdacContext;
\ No newline at end of file