github.com/alexdevranger/node-1.8.27@v0.0.0-20221128213301-aa5841e41d2d/dashboard/assets/components/Main.jsx (about)

     1  // @flow
     2  
     3  // Copyright 2017 The go-ethereum Authors
     4  // This file is part of the go-dubxcoin library.
     5  //
     6  // The go-dubxcoin library is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU Lesser General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // (at your option) any later version.
    10  //
    11  // The go-dubxcoin library is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    14  // GNU Lesser General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU Lesser General Public License
    17  // along with the go-dubxcoin library. If not, see <http://www.gnu.org/licenses/>.
    18  
    19  import React, { Component } from "react";
    20  
    21  import withStyles from "material-ui/styles/withStyles";
    22  
    23  import { MENU } from "../common";
    24  import Logs from "./Logs";
    25  import Footer from "./Footer";
    26  import type { Content } from "../types/content";
    27  
    28  // styles contains the constant styles of the component.
    29  const styles = {
    30    wrapper: {
    31      display: "flex",
    32      flexDirection: "column",
    33      width: "100%",
    34    },
    35    content: {
    36      flex: 1,
    37      overflow: "auto",
    38    },
    39  };
    40  
    41  // themeStyles returns the styles generated from the theme for the component.
    42  const themeStyles = (theme) => ({
    43    content: {
    44      backgroundColor: theme.palette.background.default,
    45      padding: theme.spacing.unit * 3,
    46    },
    47  });
    48  
    49  export type Props = {
    50    classes: Object,
    51    active: string,
    52    content: Content,
    53    shouldUpdate: Object,
    54    send: (string) => void,
    55  };
    56  
    57  // Main renders the chosen content.
    58  class Main extends Component<Props> {
    59    constructor(props) {
    60      super(props);
    61      this.container = React.createRef();
    62      this.content = React.createRef();
    63    }
    64  
    65    getSnapshotBeforeUpdate() {
    66      if (this.content && typeof this.content.beforeUpdate === "function") {
    67        return this.content.beforeUpdate();
    68      }
    69      return null;
    70    }
    71  
    72    componentDidUpdate(prevProps, prevState, snapshot) {
    73      if (this.content && typeof this.content.didUpdate === "function") {
    74        this.content.didUpdate(prevProps, prevState, snapshot);
    75      }
    76    }
    77  
    78    onScroll = () => {
    79      if (this.content && typeof this.content.onScroll === "function") {
    80        this.content.onScroll();
    81      }
    82    };
    83  
    84    render() {
    85      const { classes, active, content, shouldUpdate } = this.props;
    86  
    87      let children = null;
    88      switch (active) {
    89        case MENU.get("home").id:
    90        case MENU.get("chain").id:
    91        case MENU.get("txpool").id:
    92        case MENU.get("network").id:
    93        case MENU.get("system").id:
    94          children = <div>Work in progress.</div>;
    95          break;
    96        case MENU.get("logs").id:
    97          children = (
    98            <Logs
    99              ref={(ref) => {
   100                this.content = ref;
   101              }}
   102              container={this.container}
   103              send={this.props.send}
   104              content={this.props.content}
   105              shouldUpdate={shouldUpdate}
   106            />
   107          );
   108      }
   109  
   110      return (
   111        <div style={styles.wrapper}>
   112          <div
   113            className={classes.content}
   114            style={styles.content}
   115            ref={(ref) => {
   116              this.container = ref;
   117            }}
   118            onScroll={this.onScroll}
   119          >
   120            {children}
   121          </div>
   122          <Footer
   123            general={content.general}
   124            system={content.system}
   125            shouldUpdate={shouldUpdate}
   126          />
   127        </div>
   128      );
   129    }
   130  }
   131  
   132  export default withStyles(themeStyles)(Main);