|
@@ -33,6 +33,11 @@ export const actions = {
|
|
type: 'PLAYER_FILE_UPLOAD_FAILURE',
|
|
type: 'PLAYER_FILE_UPLOAD_FAILURE',
|
|
alert: { type: 'warning', text: error.toString() }
|
|
alert: { type: 'warning', text: error.toString() }
|
|
}
|
|
}
|
|
|
|
+ },
|
|
|
|
+ filterPlayers: () => {
|
|
|
|
+ return {
|
|
|
|
+ type: 'PLAYER_FILTER'
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
console.log('State actions', actions)
|
|
console.log('State actions', actions)
|
|
@@ -41,7 +46,7 @@ console.log('State actions', actions)
|
|
export const state = {
|
|
export const state = {
|
|
allPlayers: [],
|
|
allPlayers: [],
|
|
filteredPlayers: [],
|
|
filteredPlayers: [],
|
|
- filters: {},
|
|
|
|
|
|
+ filters: [],
|
|
fileUpload: 'idle',
|
|
fileUpload: 'idle',
|
|
file: null
|
|
file: null
|
|
}
|
|
}
|
|
@@ -50,14 +55,18 @@ console.log('State state', state)
|
|
/** reducer is called by the redux dispatcher and handles all component actions */
|
|
/** reducer is called by the redux dispatcher and handles all component actions */
|
|
export function reducer (state = [], action) {
|
|
export function reducer (state = [], action) {
|
|
switch (action.type) {
|
|
switch (action.type) {
|
|
- case 'SET_PLAYERS':
|
|
|
|
- return { ...state, allPlayers: action.players }
|
|
|
|
case 'PLAYER_FILE_UPLOAD_START':
|
|
case 'PLAYER_FILE_UPLOAD_START':
|
|
return { ...state, fileUpload: 'started', file: action.file }
|
|
return { ...state, fileUpload: 'started', file: action.file }
|
|
case 'PLAYER_FILE_UPLOAD_SUCCESS':
|
|
case 'PLAYER_FILE_UPLOAD_SUCCESS':
|
|
return { ...state, fileUpload: 'finished', allPlayers: action.allPlayers }
|
|
return { ...state, fileUpload: 'finished', allPlayers: action.allPlayers }
|
|
case 'PLAYER_FILE_UPLOAD_FAILURE':
|
|
case 'PLAYER_FILE_UPLOAD_FAILURE':
|
|
return { ...state, fileUpload: 'failure' }
|
|
return { ...state, fileUpload: 'failure' }
|
|
|
|
+ case 'PLAYER_FILTER':
|
|
|
|
+ const { allPlayers, filters } = state
|
|
|
|
+ const filteredPlayers = allPlayers.filter(player =>
|
|
|
|
+ filters.length ? filters.map(filter => filter(player)).every() : true
|
|
|
|
+ )
|
|
|
|
+ return { ...state, filteredPlayers }
|
|
default:
|
|
default:
|
|
return state
|
|
return state
|
|
}
|
|
}
|
|
@@ -69,6 +78,7 @@ function * uploadFile (action) {
|
|
const allPlayers = yield call(generatePlayerList, action.file)
|
|
const allPlayers = yield call(generatePlayerList, action.file)
|
|
console.log('PlayerList success!', actions.fileUploadSuccess(allPlayers))
|
|
console.log('PlayerList success!', actions.fileUploadSuccess(allPlayers))
|
|
yield put(actions.fileUploadSuccess(allPlayers))
|
|
yield put(actions.fileUploadSuccess(allPlayers))
|
|
|
|
+ yield put(actions.filterPlayers())
|
|
} catch (error) {
|
|
} catch (error) {
|
|
console.log('PlayerList failure!', actions.fileUploadFailure(error))
|
|
console.log('PlayerList failure!', actions.fileUploadFailure(error))
|
|
yield put(actions.fileUploadFailure(error))
|
|
yield put(actions.fileUploadFailure(error))
|