From 87b6fdfadbf426500ca6a07bcbf4accb28f4f670 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Mon, 6 Jul 2020 09:29:43 -0700 Subject: [PATCH 1/2] build successful. Manually porting Andre's code --- gatsby-node.js | 28 ++--- package.json | 1 - src/components/admin-lte/index.js | 167 +++++++++++++----------------- src/components/menu-components.js | 5 + 4 files changed, 83 insertions(+), 118 deletions(-) create mode 100644 src/components/menu-components.js diff --git a/gatsby-node.js b/gatsby-node.js index f72d342..3a87b65 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -4,6 +4,7 @@ exports.onCreateWebpackConfig = ({ stage, actions, getConfig }) => { fs: "empty", }, }) + //Ignore css order if (stage === "build-javascript") { const config = getConfig() @@ -17,25 +18,10 @@ exports.onCreateWebpackConfig = ({ stage, actions, getConfig }) => { } } -exports.sourceNodes = ({ actions, createNodeId, createContentDigest }) => { - const { createNode } = actions - const defaultMenuItems = [ - { - title: "Audit", - icon: "fas-cog", - component: "./audit" - } - ] - - createNode({ - menuItems: defaultMenuItems, - id: `bch-wallet-plugins`, - parent: null, - children: [], - internal: { - type: `BchWalletPlugins`, - contentDigest: createContentDigest({}) - } - }) +exports.createPages = async ({ actions }, themeOptions) => { + const basePath = "/" + actions.createPage({ + path: basePath, + component: require.resolve("./src/pages/index.js"), + }) } - diff --git a/package.json b/package.json index 668c63a..423c454 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "version": "1.0.0", "author": "Chris Troutner ", "dependencies": { - "@loadable/component": "^5.13.0", "adminlte-2-react": "^0.1.27", "gatsby": "^2.22.15", "gatsby-image": "^2.4.5", diff --git a/src/components/admin-lte/index.js b/src/components/admin-lte/index.js index e8938c4..064ff38 100644 --- a/src/components/admin-lte/index.js +++ b/src/components/admin-lte/index.js @@ -3,6 +3,7 @@ import PropTypes from "prop-types" import Configure from "./configure" import Tokens from "./tokens" import Wallet from "./wallet" +// import Audit from "./audit" import AdminLTE, { Sidebar, Navbar } from "adminlte-2-react" import ScannerModal from "../qr-scanner/modal" @@ -12,9 +13,7 @@ import "./admin-lte.css" import BchWallet from "minimal-slp-wallet" import VersionStatus from "../version-status" import { BrowserRouter as Router } from "react-router-dom" - -import { StaticQuery, graphql } from "gatsby" -import loadable from "@loadable/component" +// import menuComponents from "../menu-components.js" import SendReceive from "./send-receive" @@ -24,10 +23,6 @@ const { Item } = Sidebar const MENU_HIDE_WIDTH = 770 let _this -const MenuItemComponent = ({ component }) => { - const RenderedComponent = loadable(() => import("./audit")) - return -} class AdminLTEPage extends React.Component { constructor(props) { @@ -48,101 +43,81 @@ class AdminLTEPage extends React.Component { , , , - + , ] render() { return ( - ( - <> - - - -
-
-

BCH Balance

+ <> + + + +
+
+

BCH Balance

-

{_this.state.bchBalance}

-
-
-
- - {_this.sidebar} - {data.bchWalletPlugins.menuItems.map(item => ( - - ))} -
- - - - -
- {_this.state.section === "Send/Receive" && ( - - )} - {_this.state.section === "Tokens" && ( - - )} - {_this.state.section === "Wallet" && ( - - )} - - {_this.state.section === "Configure" && ( - - )} - {data.bchWalletPlugins.menuItems.map( - item => - _this.state.section === item.title && ( - - ) - )} +

{_this.state.bchBalance}

-
-
- - - - - )} - /> +
+ + + {_this.sidebar} + + + + + + + + +
+ {_this.state.section === "Send/Receive" && ( + + )} + + {_this.state.section === "Tokens" && ( + + )} + + {_this.state.section === "Wallet" && ( + + )} + + {_this.state.section === "Configure" && ( + + )} + + + +
+
+ + + + + ) } // Get wallet balance diff --git a/src/components/menu-components.js b/src/components/menu-components.js new file mode 100644 index 0000000..a97529e --- /dev/null +++ b/src/components/menu-components.js @@ -0,0 +1,5 @@ +const MenuComponents = () => { + +} + +export default MenuComponents; From 9b0df4c1922d6558bd11415c00a515065190ef5c Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Mon, 6 Jul 2020 10:12:29 -0700 Subject: [PATCH 2/2] Added dynamic menu --- src/components/admin-lte/index.js | 33 +++++++++++++++++++++++++++---- src/components/menu-components.js | 6 ++---- src/pages/index.js | 10 +++++++++- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/components/admin-lte/index.js b/src/components/admin-lte/index.js index 064ff38..4d8b73d 100644 --- a/src/components/admin-lte/index.js +++ b/src/components/admin-lte/index.js @@ -13,7 +13,7 @@ import "./admin-lte.css" import BchWallet from "minimal-slp-wallet" import VersionStatus from "../version-status" import { BrowserRouter as Router } from "react-router-dom" -// import menuComponents from "../menu-components.js" +import menuComponents from "../menu-components.js" import SendReceive from "./send-receive" @@ -63,7 +63,7 @@ class AdminLTEPage extends React.Component { {_this.sidebar} - + {_this.renderNewMenuItems()} @@ -105,8 +105,7 @@ class AdminLTEPage extends React.Component { /> )} - - + {_this.renderNewViewItems()}
@@ -259,6 +258,32 @@ class AdminLTEPage extends React.Component { showScannerModal: !_this.state.showScannerModal, }) } + + // Render non-default menu items. The catch ensures that the render function + // won't be interrupted if there is an issue porting new menu items. + renderNewMenuItems() { + try { + return menuComponents && menuComponents.map(m => m.menuItem) + } catch (err) { + // TODO: Figure out how to return an invisible Item. + return + } + + } + + // Displays the View corresponding to the dynamically loaded menu item. + renderNewViewItems() { + try { + return(menuComponents && menuComponents.map(m => { + if (_this.state.section === m.key) { + return m.component + } + return "" + })) + } catch(err) { + + } + } } // Props prvided by redux AdminLTEPage.propTypes = { diff --git a/src/components/menu-components.js b/src/components/menu-components.js index a97529e..443bc69 100644 --- a/src/components/menu-components.js +++ b/src/components/menu-components.js @@ -1,5 +1,3 @@ -const MenuComponents = () => { +const MenuComponents = () => {} -} - -export default MenuComponents; +export default MenuComponents diff --git a/src/pages/index.js b/src/pages/index.js index f73097b..7400b40 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -5,7 +5,8 @@ let AdminLTE = typeof window !== `undefined` ? require("../components/admin-lte").default : null -// Maps the props that are going to be sended + +// Maps the props that are going to be sended // to the component connected with Redux const mapStateToProps = ({ walletInfo, bchBalance, bchWallet }) => { return { walletInfo, bchBalance, bchWallet } @@ -34,4 +35,11 @@ class AdminLTEPage extends React.Component { } } +// const AdminLTEPage = props => { +// <> +// {ConnectedDashboard && +// ()} +// +// } + export default AdminLTEPage