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

98 lines
3.0 KiB
JavaScript
Raw Normal View History

2018-11-08 18:08:07 +01:00
import React from 'react';
2019-02-17 00:17:38 +01:00
import { Route, Switch, withRouter, matchPath } from 'react-router-dom';
2019-01-14 19:23:29 +01:00
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';
import Suggestion from './Suggestion';
2018-12-15 00:24:41 +01:00
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,
isInfoToggled: false,
2019-02-12 16:55:46 +01:00
videoId: localStorage['lastId']
2019-01-14 19:23:29 +01:00
};
2019-02-17 00:17:38 +01:00
// componentDidMount() {
2019-01-14 19:23:29 +01:00
2019-02-17 00:17:38 +01:00
// }
2019-01-14 19:23:29 +01:00
2019-02-17 00:17:38 +01:00
// componentDidUpdate(prevProps, prevState) {
2019-01-14 19:23:29 +01:00
2019-02-17 00:17:38 +01:00
// }
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 };
2019-01-14 19:23:29 +01:00
}
2019-02-17 00:17:38 +01:00
return null;
}
2019-01-14 19:23:29 +01:00
render() {
2018-11-08 18:08:07 +01:00
return (
<React.Fragment>
2019-02-17 00:17:38 +01:00
<Row id="top">
2018-12-15 00:24:41 +01:00
<TopBar />
2019-02-17 00:17:38 +01:00
</Row>
<Row className="upperSection">
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">
2019-02-17 00:17:38 +01:00
<ReactHeight onHeightReady={height => { this.setState({ playerHeight: height }) }}>
<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 }}
2019-02-17 00:17:38 +01:00
className="p-0 p-xs-0"
style={window.innerWidth < 992 ?
{ 'overflow': "auto", 'display': 'fixed', 'maxHeight': this.state.playerHeight * 1.4 + 'px' } :
{ 'overflow': "auto", 'maxHeight': `${this.state.playerHeight}px` }}>
2019-02-16 17:55:35 +01:00
{/* 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-17 00:17:38 +01:00
<Route render={(props) => <VideoInfo {...props} key={this.state.videoId} videoId={this.state.videoId} />} />
</div>
</Collapse>
2018-12-12 20:14:39 +01:00
</Col>
2019-02-17 00:17:38 +01:00
</Row>
<Row style={{ "maxHeight": `calc(98vh - ${this.state.playerHeight}px - 46px)` }} 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);