From 7af8c632b029419ec9b701aca4f8e80c98120cdc Mon Sep 17 00:00:00 2001
From: Steffen Vogel
Date: Wed, 20 Sep 2017 13:57:59 +0200
Subject: [PATCH] home screen is now a component instead of a container
---
src/{containers => components}/home.js | 43 +++++++++++---------------
src/containers/app.js | 2 +-
2 files changed, 19 insertions(+), 26 deletions(-)
rename src/{containers => components}/home.js (75%)
diff --git a/src/containers/home.js b/src/components/home.js
similarity index 75%
rename from src/containers/home.js
rename to src/components/home.js
index c365f0f..82d4a1e 100644
--- a/src/containers/home.js
+++ b/src/components/home.js
@@ -19,39 +19,31 @@
* along with VILLASweb. If not, see .
******************************************************************************/
-import React, { Component } from 'react';
-import { Container } from 'flux/utils';
+import React from 'react';
-import AppDispatcher from '../app-dispatcher';
+import { Link } from 'react-router-dom';
-import NodeStore from '../stores/node-store';
-import SimulationStore from '../stores/simulation-store';
-import ProjectStore from '../stores/project-store';
+import RestAPI from '../api/rest-api';
import config from '../config';
-class Home extends Component {
- static getStores() {
- return [ NodeStore, SimulationStore, ProjectStore ];
+class Home extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {};
}
- static calculateState() {
- return {
- nodes: NodeStore.getState(),
- projects: ProjectStore.getState(),
- simulations: SimulationStore.getState(),
- };
+ getCounts(type) {
+ if (this.state.hasOwnProperty('counts'))
+ return this.state.counts[type];
+ else
+ return '?';
}
componentWillMount() {
- AppDispatcher.dispatch({
- type: 'projects/start-load',
- token: this.state.sessionToken
- });
-
- AppDispatcher.dispatch({
- type: 'simulations/start-load',
- token: this.state.sessionToken
+ RestAPI.get('/api/v1/counts').then(response => {
+ this.setState({ counts: response });
+ console.log(response);
});
}
@@ -65,7 +57,8 @@ class Home extends Component {
VILLASweb is a frontend for distributed real-time simulation hosted by {config.admin.name}.
- This instance is hosting {this.state.projects.length} projects consisting of {this.state.nodes.length} nodes and {this.state.simulations.length} simulations.
+ This instance is hosting {this.getCounts('projects')} projects consisting of {this.getCounts('nodes')} nodes, {this.getCounts('visualizations')} visualizations and {this.getCounts('simulators')} simulations.
+ A total of {this.getCounts('users')} users are registered.
@@ -94,4 +87,4 @@ class Home extends Component {
}
}
-export default Container.create(Home);
+export default Home;
diff --git a/src/containers/app.js b/src/containers/app.js
index d4edcea..85a2b63 100644
--- a/src/containers/app.js
+++ b/src/containers/app.js
@@ -35,12 +35,12 @@ import UserStore from '../stores/user-store';
import DesignStore from '../stores/design-store';
import NotificationsDataManager from '../data-managers/notifications-data-manager';
+import Home from '../components/home';
import Header from '../components/header';
import Footer from '../components/footer';
import SidebarMenu from '../components/menu-sidebar';
import HeaderMenu from '../components/header-menu';
-import Home from './home';
import Projects from './projects';
import Project from './project';
import Simulators from './simulators';