From be5e95b6cfe85b92844fae9dc8967cd7c210d762 Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Fri, 2 Sep 2016 20:38:01 +0000 Subject: [PATCH] fixed routing --- client/js/app.js | 18 ++++------ client/js/components/Post.js | 21 ++++++++++-- client/js/components/Preview.js | 26 +++++++++++---- client/js/components/sensors/SensorInfo.js | 11 +++++++ client/js/components/utils/Loading.js | 14 ++++++++ client/js/pages/Index.js | 38 ++-------------------- 6 files changed, 72 insertions(+), 56 deletions(-) create mode 100644 client/js/components/sensors/SensorInfo.js create mode 100644 client/js/components/utils/Loading.js diff --git a/client/js/app.js b/client/js/app.js index 54c9c80..f8913dc 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -12,14 +12,9 @@ import store, {history} from './redux/store'; import * as actions from './redux/actions'; import Index from './pages/Index'; - -class Main extends React.Component { - render() { - return ( -
{React.cloneElement(this.props.children, this.props)}
- ); - } -} +import Preview from './components/Preview'; +import Post from './components/Post'; +import SensorInfo from './components/sensors/SensorInfo'; function mapStateToProps(state) { return { @@ -33,14 +28,15 @@ function mapDispatchToProps(dispatch) { } } -const App = connect(mapStateToProps, mapDispatchToProps)(Main); +const App = connect(mapStateToProps, mapDispatchToProps)(Index); ReactDOM.render(( - - + + + diff --git a/client/js/components/Post.js b/client/js/components/Post.js index a6c0d0a..4f1d13a 100644 --- a/client/js/components/Post.js +++ b/client/js/components/Post.js @@ -3,6 +3,9 @@ import marked from 'marked'; import React from 'react'; import {Link} from 'react-router'; +//components +import Loading from './utils/Loading'; + import '../../assets/scss/Content.scss'; const renderer = new marked.Renderer(); @@ -16,13 +19,25 @@ marked.setOptions({ export default class Post extends React.Component { + componentDidMount() { + const params = this.props.params; + this.props.actions.fetchPost(params.category, params.post); + } + render() { + const post = this.props.redux.post; + const fetched = this.props.redux.fetched; + const fetching = this.props.redux.fetching; + return (
-
+ {fetched ? +
+
+ Home +
+ : }
- Home -
); } } diff --git a/client/js/components/Preview.js b/client/js/components/Preview.js index c37b087..bfeaae9 100644 --- a/client/js/components/Preview.js +++ b/client/js/components/Preview.js @@ -1,13 +1,20 @@ import React from 'react'; import {Link} from 'react-router'; +//components +import Loading from './utils/Loading'; + import '../../assets/scss/Content.scss'; export default class Preview extends React.Component { + componentDidMount() { + this.props.actions.fetchPreview(); + } + insertPosts(posts) { let elements = []; - for (let i = 0; i < this.props.postLimit && i < posts.length; i++) { + for (let i = 0; i < this.props.redux.postLimit && i < posts.length; i++) { elements.push(
@@ -27,14 +34,21 @@ export default class Preview extends React.Component { } render() { - const posts = this.props.posts; + const posts = this.props.redux.preview.posts; + const postLimit = this.props.redux.postLimit; + const increasePostLimit = this.props.actions.increasePostLimit; + const fetched = this.props.redux.fetched; return (
- {posts.length > 0 ? this.insertPosts(posts): null} - {posts.length > this.props.postLimit ? - - : null} + {fetched ? +
+ {posts.length > 0 ? this.insertPosts(posts): null} + {posts.length > postLimit ? + + : null} +
+ : }
); } diff --git a/client/js/components/sensors/SensorInfo.js b/client/js/components/sensors/SensorInfo.js new file mode 100644 index 0000000..38c80fc --- /dev/null +++ b/client/js/components/sensors/SensorInfo.js @@ -0,0 +1,11 @@ +import React from 'react'; + +export default class SensorInfo extends React.Component{ + + + render(){ + return( +
Test123
+ ); + } +} \ No newline at end of file diff --git a/client/js/components/utils/Loading.js b/client/js/components/utils/Loading.js new file mode 100644 index 0000000..8b59fe9 --- /dev/null +++ b/client/js/components/utils/Loading.js @@ -0,0 +1,14 @@ +import React from 'react'; + +//loading icon +import loading from '../../../assets/images/loading.svg'; + +export default class Loading extends React.Component{ + render(){ + return( +
+ loading... +
+ ); + } +} \ No newline at end of file diff --git a/client/js/pages/Index.js b/client/js/pages/Index.js index c6aa2f3..33c1408 100644 --- a/client/js/pages/Index.js +++ b/client/js/pages/Index.js @@ -2,10 +2,8 @@ import React from 'react'; //components import Header from '../components/Header'; -import Preview from '../components/Preview'; import Footer from '../components/Footer'; import Sidebar from '../components/Sidebar'; -import Post from '../components/Post'; //css import '../../assets/css/normalize.css'; @@ -13,50 +11,18 @@ import '../../assets/scss/main.scss'; import 'font-awesome/css/font-awesome.min.css'; import '../../assets/css/dracula.css'; -//loading icon -import loading from '../../assets/images/loading.svg'; - export default class Index extends React.Component { - componentDidMount() { - this.props.actions.fetchPreview(); - this.page = this.props.params.page; - this.page === 'post' ? this.props.actions.fetchPost(this.props.params.category, this.props.params.post) : ""; - } - - componentWillReceiveProps(nextProps) { - if (this.props.params !== nextProps.params) { - const params = nextProps.params; - this.page = params.page; - - if (typeof params.post !== 'undefined' && typeof params.category !== 'undefined') { - this.props.actions.fetchPost(params.category, params.post); - } - } - } render() { - const fetched = this.props.redux.fetched; - const fetching = this.props.redux.fetching; - return (
- {typeof this.page === 'undefined' && !fetching - ? - : null} - {this.page === 'post' && !fetching ? : null} - {fetching ? loadingElement : null} + {React.cloneElement(this.props.children, this.props)}
); } -} - -const loadingElement =
- loading... -
; +} \ No newline at end of file