This repository has been archived on 2019-10-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tecnologiabanana/src/App.js
T

99 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-11-08 18:08:07 +01:00
import React from 'react';
2019-02-16 17:55:35 +01:00
import { Route, Switch, withRouter, matchPath, HashRouter } from 'react-router-dom';
2019-01-14 19:23:29 +01:00
import 'bootstrap/dist/css/bootstrap.css';
import { Row, Col, Button, Collapse } from 'react-bootstrap';
import TopBar from './TopBar';
import VideoPlayer from './VideoPlayer';
2018-11-15 18:33:17 +01:00
import VideoInfo from './VideoInfo';
2019-01-14 19:23:29 +01:00
import VideoList from './VideoList';
2018-12-15 00:24:41 +01:00
import Suggestion from './areainfo/Suggestion';
import { ReactHeight } from 'react-height';
import './css/App.css';
2018-11-08 17:54:37 +01:00
2019-01-30 21:43:15 +01:00
2018-11-08 18:08:07 +01:00
class App extends React.Component {
2019-01-14 19:23:29 +01:00
state = {
playerHeight: null,
navHeight: null,
blackbgHeight: null,
2019-02-16 17:55:35 +01:00
dirtyBg: true,
2019-01-14 19:23:29 +01:00
isInfoToggled: false,
2019-02-12 16:55:46 +01:00
videoId: localStorage['lastId']
2019-01-14 19:23:29 +01:00
};
// componentDidMount(){
// }
// componentDidUpdate(prevProps, prevState) {
// }
static getDerivedStateFromProps(nextProps, prevState) {
let idMatch = matchPath(nextProps.location.pathname, {
path: "/video/:id",
exact: true,
strict: false
});
if(idMatch && idMatch.params.id !== prevState.videoId){
localStorage.setItem('lastId', idMatch.params.id)
return {videoId: idMatch.params.id };
}
return null;
}
2019-01-14 19:23:29 +01:00
render() {
2018-11-08 18:08:07 +01:00
return (
<React.Fragment>
2019-02-16 17:55:35 +01:00
{/* <HashRouter/> */}
2019-01-14 19:23:29 +01:00
<ReactHeight className="row" onHeightReady={height => { this.setState({ navHeight: height }); }}>
2018-12-15 00:24:41 +01:00
<TopBar />
2018-12-14 17:53:15 +01:00
</ReactHeight>
2019-02-16 17:55:35 +01:00
<ReactHeight dirty={this.state.dirtyBg} onHeightReady={height => this.setState({ blackbgHeight: height, dirtyBg: false })} className="row upperSection p-2 px-5" >
2018-12-15 00:24:41 +01:00
<Col
xs="12"
2018-12-27 19:26:46 +01:00
lg={this.state.isInfoToggled ? { span: 6, offset: 0, order: 2 } : { span: 7, offset: 1, order: 2 }}
2018-12-15 00:24:41 +01:00
className="align-content-center pt-2 p-1 pr-2">
<ReactHeight onHeightReady={height => this.setState({ playerHeight: height })}>
2019-01-14 19:23:29 +01:00
<VideoPlayer videoId={this.state.videoId}/>
2018-12-15 00:24:41 +01:00
</ReactHeight>
2018-11-08 18:08:07 +01:00
</Col>
2018-12-15 00:24:41 +01:00
<Col
xs="12"
2018-12-16 02:16:01 +01:00
lg={this.state.isInfoToggled ? { span: 5, order: 1 } : { span: 3, order: 1 }}
className="p-0 p-sm-0"
2019-02-16 17:55:35 +01:00
style={window.innerWidth < 992 ? { 'overflow': "auto", 'display':'fixed' , 'maxHeight':this.state.playerHeight*1.4+'px'} : { 'overflow': "auto" , 'maxHeight':`${this.state.playerHeight}px`}}>
{/* true = style for xs ;; false = style for lg */}
2019-02-14 17:01:45 +01:00
<div className="d-flex justify-content-center">
2019-01-14 19:23:29 +01:00
<Button
variant="outline-light"
2019-02-16 17:55:35 +01:00
onClick={() => this.setState({ isInfoToggled: !this.state.isInfoToggled, dirtyBg: true })}
2019-01-14 19:23:29 +01:00
className="pt-1 "
aria-controls="infovideo-collapse"
aria-expanded={this.state.isInfoToggled}>
{this.state.isInfoToggled ? "Nascondi informazioni" : "Mostra informazioni"}
</Button>
</div>
<Collapse in={this.state.isInfoToggled}>
2018-12-15 00:24:41 +01:00
<div className="pt-1" id="infovideo-collapse">
2019-02-16 17:55:35 +01:00
<Route render={(props)=> <VideoInfo {...props} videoId={this.state.videoId}/>} />
</div>
</Collapse>
2018-12-12 20:14:39 +01:00
</Col>
2018-12-15 00:24:41 +01:00
</ReactHeight>
2019-02-14 17:01:45 +01:00
<Row style={{ "maxHeight": `calc(98vh - ${this.state.blackbgHeight}px - ${this.state.navHeight}px)` }} className='mt-1 downSection'>
<Switch>
<Route exact path='/' component={VideoList} />
2019-02-14 17:01:45 +01:00
<Route path={"/video/:id"} component={Suggestion} />
<Route path={"/search/:query"} component={Suggestion} />
<Route render={() => <div>URL not found</div>} />
2018-11-14 15:08:21 +01:00
</Switch>
2018-11-08 18:08:07 +01:00
</Row>
</React.Fragment>
);
}
2018-11-08 17:54:37 +01:00
}
2019-01-14 19:23:29 +01:00
export default withRouter(App);