diff --git a/js/api.js b/js/api.js index 88a9795..2e7d1a4 100644 --- a/js/api.js +++ b/js/api.js @@ -346,10 +346,10 @@ const reducer_tournamentlist = (state = defaultstate_tournamentlist, action) => getRequest(action.state, '/tournaments?type=' + action.parameters.type).then((resp) => { __store.dispatch({ type: actiontypes_tournamentlist.FETCH_SUCCESS, - parameters: resp + parameters: resp.data }); storeOptionalToken(resp); - action.parameters.successCallback(); + action.parameters.successCallback(resp.data); }).catch((error) => { __store.dispatch({ type: actiontypes_tournamentlist.FETCH_ERROR, @@ -360,7 +360,7 @@ const reducer_tournamentlist = (state = defaultstate_tournamentlist, action) => }); return state; case actiontypes_tournamentlist.FETCH_SUCCESS: - return Object.assign({}, state, {...action.parameters}); + return Object.assign({}, state, {tournaments: action.parameters}); case actiontypes_tournamentlist.FETCH_ERROR: return state; default: @@ -485,11 +485,11 @@ export function getState() { return __store.getState(); } -export function requestTournamentList(myType, successCallback, errorCallback) { +export function requestTournamentList(type, successCallback, errorCallback) { __store.dispatch({ type: actiontypes_tournamentlist.FETCH, parameters: { - type: myType, + type: type, successCallback: successCallback, errorCallback: errorCallback }, diff --git a/js/components/TournamentList.js b/js/components/TournamentList.js new file mode 100644 index 0000000..53055b8 --- /dev/null +++ b/js/components/TournamentList.js @@ -0,0 +1,45 @@ +import React from 'react'; +import {requestTournamentList} from '../api'; + +export default class TournamentList extends React.Component { + constructor(props) { + super(props); + this.state = { + error: null, + tournaments: [] + }; + } + + componentDidMount() { + requestTournamentList(this.props.type, tournaments => { + this.setState({ + tournaments: tournaments + }); + }, + error => { + this.setState({ + error + }); + }); + } + + render() { + if (this.state.tournaments.length === 0) { + return
keine + Turniere vorhanden
; + } else { + return this.state.tournaments.map(item => ( + //The code should be item.code but the api just supports it this way by now +