|
@@ -1,5 +1,5 @@
|
|
|
/** @module player/state */
|
|
|
-import { put, takeEvery } from 'redux-saga/effects'
|
|
|
+import { call, put, takeEvery } from 'redux-saga/effects'
|
|
|
import { generatePlayerList } from './functions'
|
|
|
|
|
|
/**
|
|
@@ -22,14 +22,16 @@ export const actions = {
|
|
|
file
|
|
|
}
|
|
|
},
|
|
|
- fileUploadSuccess: () => {
|
|
|
+ fileUploadSuccess: allPlayers => {
|
|
|
return {
|
|
|
- type: 'PLAYER_FILE_UPLOAD_SUCCESS'
|
|
|
+ type: 'PLAYER_FILE_UPLOAD_SUCCESS',
|
|
|
+ allPlayers
|
|
|
}
|
|
|
},
|
|
|
- fileUploadFailure: () => {
|
|
|
+ fileUploadFailure: error => {
|
|
|
return {
|
|
|
- type: 'PLAYER_FILE_UPLOAD_FAILURE'
|
|
|
+ type: 'PLAYER_FILE_UPLOAD_FAILURE',
|
|
|
+ alert: { type: 'warning', text: error.toString() }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -53,7 +55,7 @@ export function reducer (state = [], action) {
|
|
|
case 'PLAYER_FILE_UPLOAD_START':
|
|
|
return { ...state, fileUpload: 'started', file: action.file }
|
|
|
case 'PLAYER_FILE_UPLOAD_SUCCESS':
|
|
|
- return { ...state, fileUpload: 'finished' }
|
|
|
+ return { ...state, fileUpload: 'finished', allPlayers: action.allPlayers }
|
|
|
case 'PLAYER_FILE_UPLOAD_FAILURE':
|
|
|
return { ...state, fileUpload: 'failure' }
|
|
|
default:
|
|
@@ -64,10 +66,12 @@ export function reducer (state = [], action) {
|
|
|
function * uploadFile (action) {
|
|
|
try {
|
|
|
console.log('PlayerList uploadFile', action.file)
|
|
|
- generatePlayerList(action.file)
|
|
|
- yield put(actions.fileUploadSuccess())
|
|
|
- } catch (e) {
|
|
|
- yield put(actions.fileUploadFailure())
|
|
|
+ const allPlayers = yield call(generatePlayerList, action.file)
|
|
|
+ console.log('PlayerList success!', actions.fileUploadSuccess(allPlayers))
|
|
|
+ yield put(actions.fileUploadSuccess(allPlayers))
|
|
|
+ } catch (error) {
|
|
|
+ console.log('PlayerList failure!', actions.fileUploadFailure(error))
|
|
|
+ yield put(actions.fileUploadFailure(error))
|
|
|
}
|
|
|
}
|
|
|
|