diff --git a/app/controllers/AdminController.js b/app/controllers/AdminController.js index e87bac9..75348c3 100644 --- a/app/controllers/AdminController.js +++ b/app/controllers/AdminController.js @@ -7,13 +7,12 @@ class AdminController { getAll(onSuccess, onError) { let collection = this.database.collection('publicStates'); - let cursor = collection.find({}, {}); - cursor.toArray((item) => { - console.log('item: ' + item); + let cursor = collection.find({}, {}).toArray(); + cursor.then((items) => { + onSuccess(items); }); - onSuccess({}); }; }; -module.exports = AdminController; \ No newline at end of file +module.exports = AdminController; diff --git a/client/src/actions/gameActions.js b/client/src/actions/gameActions.js index 29d08a5..c0c5722 100644 --- a/client/src/actions/gameActions.js +++ b/client/src/actions/gameActions.js @@ -1,19 +1,35 @@ import ApiGameService from '../services/ApiGameService'; import { - PUBLIC_STATE_CREATED + PUBLIC_STATE_CREATED, + PUBLIC_STATES_LOADED } from './types'; export const createPublicState = (requestData, onSuccess, onError) => dispatch => { const service = new ApiGameService(); const scb = (data) => { - dispatch({ - type: PUBLIC_STATE_CREATED, - data: data - }); - if (onSuccess) onSuccess(data); + dispatch({ + type: PUBLIC_STATE_CREATED, + data: data + }); + if (onSuccess) onSuccess(data); }; const ecb = (error) => { - if (onError) onError(error); + if (onError) onError(error); }; service.createPublicState(requestData, scb, ecb); }; + +export const loadPublicStates = (onSuccess, onError) => dispatch => { + const service = new ApiGameService(); + const scb = (data) => { + dispatch({ + type: PUBLIC_STATES_LOADED, + data: data + }); + if (onSuccess) onSuccess(data); + }; + const ecb = (error) => { + if (onError) onError(error); + }; + service.getPublicStates(scb, ecb); +}; diff --git a/client/src/actions/types.js b/client/src/actions/types.js index d85d8ea..b46420d 100644 --- a/client/src/actions/types.js +++ b/client/src/actions/types.js @@ -1,7 +1,9 @@ export const USER_AUTHENTICATED = 'USER_AUTHENTICATED'; export const USER_LOGGED_OUT = 'USER_LOGGED_OUT'; export const USER_REGISTERED = 'USER_REGISTERED'; + +export const PUBLIC_STATE_CREATED = 'PUBLIC_STATE_CREATED'; +export const PUBLIC_STATES_LOADED = 'PUBLIC_STATES_LOADED'; + export const QUESTIONS_LOADED = 'QUESTIONS_LOADED'; export const QUESTIONS_LOAD_ERROR = 'QUESTIONS_LOADED'; - -export const PUBLIC_STATE_CREATED = 'PUBLIC_STATE_CREATED'; \ No newline at end of file diff --git a/client/src/components/PublicStateList/PublicStateList.js b/client/src/components/PublicStateList/PublicStateList.js index 2041cf9..aeb5515 100644 --- a/client/src/components/PublicStateList/PublicStateList.js +++ b/client/src/components/PublicStateList/PublicStateList.js @@ -1,15 +1,40 @@ import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { loadPublicStates } from '../../actions/gameActions'; +import { connect } from 'react-redux'; class PublicStateList extends Component { + componentDidMount() { + this.props.loadPublicStates(); + }; + render() { + + console.log('public states: ' + this.props.publicStates); + + const pubStateList = this.props.publicStates.map((ps) => { + return ( +