qotnews/webclient/src/App.js

57 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-08-24 05:04:51 +00:00
import React from 'react';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import './Style-light.css';
import './Style-dark.css';
2019-08-25 07:46:58 +00:00
import './fonts/Fonts.css';
2019-08-24 05:04:51 +00:00
import Feed from './Feed.js';
import Article from './Article.js';
import Comments from './Comments.js';
import ScrollToTop from './ScrollToTop.js';
2019-08-24 05:04:51 +00:00
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
theme: localStorage.getItem('theme') || '',
};
}
light() {
this.setState({ theme: '' });
localStorage.setItem('theme', '');
}
dark() {
this.setState({ theme: 'dark' });
localStorage.setItem('theme', 'dark');
}
render() {
const theme = this.state.theme;
2019-08-25 07:46:58 +00:00
document.body.style.backgroundColor = theme === 'dark' ? '#000' : '#eeeeee';
2019-08-24 05:04:51 +00:00
return (
<div className={theme}>
<Router>
<div className='container menu'>
<p>
<Link to='/'>QotNews - Feed</Link>
2019-08-24 05:04:51 +00:00
<span className='theme'>Theme: <a href='#' onClick={() => this.light()}>Light</a> - <a href='#' onClick={() => this.dark()}>Dark</a></span>
<br />
<span className='slogan'>Reddit, Hacker News, and Tildes combined, then pre-rendered in reader mode.</span>
2019-08-24 05:04:51 +00:00
</p>
</div>
<Route path='/' exact component={Feed} />
<Route path='/:id/c' exact component={Comments} />
<Route path='/:id' exact component={Article} />
<ScrollToTop />
2019-08-24 05:04:51 +00:00
</Router>
</div>
);
}
}
export default App;