Main.jsx 3.2 KB

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