Main.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 Network from 'Network';
  20. import Logs from 'Logs';
  21. import Footer from 'Footer';
  22. import {MENU} from '../common';
  23. import type {Content} from '../types/content';
  24. // styles contains the constant styles of the component.
  25. const styles = {
  26. wrapper: {
  27. display: 'flex',
  28. flexDirection: 'column',
  29. width: '100%',
  30. },
  31. content: {
  32. flex: 1,
  33. overflow: 'auto',
  34. },
  35. };
  36. // themeStyles returns the styles generated from the theme for the component.
  37. const themeStyles = theme => ({
  38. content: {
  39. backgroundColor: theme.palette.background.default,
  40. padding: theme.spacing.unit * 3,
  41. },
  42. });
  43. export type Props = {
  44. classes: Object,
  45. active: string,
  46. content: Content,
  47. shouldUpdate: Object,
  48. send: string => void,
  49. };
  50. type State = {};
  51. // Main renders the chosen content.
  52. class Main extends Component<Props, State> {
  53. constructor(props) {
  54. super(props);
  55. this.container = React.createRef();
  56. this.content = React.createRef();
  57. }
  58. componentDidUpdate(prevProps, prevState, snapshot) {
  59. if (this.content && typeof this.content.didUpdate === 'function') {
  60. this.content.didUpdate(prevProps, prevState, snapshot);
  61. }
  62. }
  63. onScroll = () => {
  64. if (this.content && typeof this.content.onScroll === 'function') {
  65. this.content.onScroll();
  66. }
  67. };
  68. getSnapshotBeforeUpdate(prevProps: Readonly<P>, prevState: Readonly<S>) {
  69. if (this.content && typeof this.content.beforeUpdate === 'function') {
  70. return this.content.beforeUpdate();
  71. }
  72. return null;
  73. }
  74. render() {
  75. const {
  76. classes, active, content, shouldUpdate,
  77. } = this.props;
  78. let children = null;
  79. switch (active) {
  80. case MENU.get('home').id:
  81. children = <div>Work in progress.</div>;
  82. break;
  83. case MENU.get('chain').id:
  84. children = <div>Work in progress.</div>;
  85. break;
  86. case MENU.get('txpool').id:
  87. children = <div>Work in progress.</div>;
  88. break;
  89. case MENU.get('network').id:
  90. children = <Network
  91. content={this.props.content.network}
  92. container={this.container}
  93. />;
  94. break;
  95. case MENU.get('system').id:
  96. children = <div>Work in progress.</div>;
  97. break;
  98. case MENU.get('logs').id:
  99. children = (
  100. <Logs
  101. ref={(ref) => { this.content = ref; }}
  102. container={this.container}
  103. send={this.props.send}
  104. content={this.props.content}
  105. shouldUpdate={shouldUpdate}
  106. />
  107. );
  108. }
  109. return (
  110. <div style={styles.wrapper}>
  111. <div
  112. className={classes.content}
  113. style={styles.content}
  114. ref={(ref) => { this.container = ref; }}
  115. onScroll={this.onScroll}
  116. >
  117. {children}
  118. </div>
  119. <Footer
  120. general={content.general}
  121. system={content.system}
  122. shouldUpdate={shouldUpdate}
  123. />
  124. </div>
  125. );
  126. }
  127. }
  128. export default withStyles(themeStyles)(Main);