github.com/xxRanger/go-ethereum@v1.8.23/dashboard/assets/components/Main.jsx (about) 1 // @flow 2 3 // Copyright 2017 The go-ethereum Authors 4 // This file is part of the go-ethereum library. 5 // 6 // The go-ethereum 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-ethereum 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-ethereum 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 { 86 classes, active, content, shouldUpdate, 87 } = this.props; 88 89 let children = null; 90 switch (active) { 91 case MENU.get('home').id: 92 case MENU.get('chain').id: 93 case MENU.get('txpool').id: 94 case MENU.get('network').id: 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 110 return ( 111 <div style={styles.wrapper}> 112 <div 113 className={classes.content} 114 style={styles.content} 115 ref={(ref) => { this.container = ref; }} 116 onScroll={this.onScroll} 117 > 118 {children} 119 </div> 120 <Footer 121 general={content.general} 122 system={content.system} 123 shouldUpdate={shouldUpdate} 124 /> 125 </div> 126 ); 127 } 128 } 129 130 export default withStyles(themeStyles)(Main);