qotnews/webclient/src/App.js

64 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-08-24 05:04:51 +00:00
import React from 'react';
2019-10-12 05:32:17 +00:00
import { BrowserRouter as Router, Route, Link, Switch } from 'react-router-dom';
2019-08-24 05:04:51 +00:00
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';
2019-10-12 05:32:17 +00:00
import Search from './Search.js';
import Results from './Results.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>
2019-10-12 05:32:17 +00:00
<Route path='/(|search)' component={Search} />
2019-08-24 05:04:51 +00:00
</div>
2019-10-12 05:32:17 +00:00
2019-08-24 05:04:51 +00:00
<Route path='/' exact component={Feed} />
2019-10-12 05:32:17 +00:00
<Switch>
<Route path='/search' component={Results} />
<Route path='/:id' exact component={Article} />
</Switch>
<Route path='/:id/c' exact component={Comments} />
<ScrollToTop />
2019-08-24 05:04:51 +00:00
</Router>
</div>
);
}
}
export default App;