Main.jsx 3.6 KB

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