From dac0c3327254b723180ed5c38251c1e5e2804027 Mon Sep 17 00:00:00 2001 From: Felix Hamme Date: Sun, 28 Apr 2019 04:18:18 +0200 Subject: [PATCH] Implement page for displaying the list of private tournaments --- js/api.js | 10 ++-- js/components/TournamentList.js | 45 ++++++++++++++++++ pages/private.js | 82 +++++++++++---------------------- 3 files changed, 76 insertions(+), 61 deletions(-) create mode 100644 js/components/TournamentList.js 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 + + )); + } + } +} + +function TournamentListEntry(props) { + return ( + + {props.name} + + ); +} \ No newline at end of file diff --git a/pages/private.js b/pages/private.js index 1d6c20c..63eaae0 100644 --- a/pages/private.js +++ b/pages/private.js @@ -8,9 +8,9 @@ import {TurniereNavigation} from '../js/components/Navigation'; import {Footer} from '../js/components/Footer'; import {Option, UserRestrictor} from '../js/components/UserRestrictor'; import {Login} from '../js/components/Login'; -import {requestTournamentList} from '../js/api'; import '../static/everypage.css'; +import TournamentList from '../js/components/TournamentList'; class PrivateTournamentsPage extends React.Component { @@ -25,9 +25,7 @@ class PrivateTournamentsPage extends React.Component { Private Turniere: turnie.re -
- -
+