|
@@ -15,31 +15,31 @@ export const actions = {
|
|
|
matchesSetFilter: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/SET_FILTER',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
filterMatches: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/FILTER_MATCHES',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
filterMatchesDone: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/FILTER_MATCHES_DONE',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
filterPlayers: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/FILTER_PLAYERS',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
filterPlayersDone: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/FILTER_PLAYERS_DONE',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
fileListRequest: () => {
|
|
@@ -47,212 +47,212 @@ export const actions = {
|
|
|
type: 'SWISSTENNIS/FILE_LIST_REQUEST',
|
|
|
}
|
|
|
},
|
|
|
- fileListSuccess: data => {
|
|
|
+ fileListSuccess: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/FILE_LIST_SUCCESS',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
- fileListFailure: error => {
|
|
|
+ fileListFailure: (error) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/FILE_LIST_FAILURE',
|
|
|
- error
|
|
|
+ error,
|
|
|
}
|
|
|
},
|
|
|
loginRequest: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/LOGIN_REQUEST',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
loginSuccess: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/LOGIN_SUCCESS',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
loginFailure: (error) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/LOGIN_FAILURE',
|
|
|
- error
|
|
|
+ error,
|
|
|
}
|
|
|
},
|
|
|
downloadPlayerListRequest: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/DOWNLOAD_PLAYERLIST_REQUEST',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
downloadPlayerListSuccess: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/DOWNLOAD_PLAYERLIST_SUCCESS',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
- downloadPlayerListFailure: error => {
|
|
|
+ downloadPlayerListFailure: (error) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/DOWNLOAD_PLAYERLIST_FAILURE',
|
|
|
- error
|
|
|
+ error,
|
|
|
}
|
|
|
},
|
|
|
parsePlayerListRequest: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/PARSE_PLAYERLIST_REQUEST',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
parsePlayerListSuccess: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/PARSE_PLAYERLIST_SUCCESS',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
- parsePlayerListFailure: error => {
|
|
|
+ parsePlayerListFailure: (error) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/PARSE_PLAYERLIST_FAILURE',
|
|
|
- error
|
|
|
+ error,
|
|
|
}
|
|
|
},
|
|
|
deletePlayerListRequest: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/DELETE_PLAYERLIST_REQUEST',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
deletePlayerListSuccess: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/DELETE_PLAYERLIST_SUCCESS',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
- deletePlayerListFailure: error => {
|
|
|
+ deletePlayerListFailure: (error) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/DELETE_PLAYERLIST_FAILURE',
|
|
|
- error
|
|
|
+ error,
|
|
|
}
|
|
|
},
|
|
|
downloadCalendarRequest: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/DOWNLOAD_CALENDAR_REQUEST',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
downloadCalendarSuccess: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/DOWNLOAD_CALENDAR_SUCCESS',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
- downloadCalendarFailure: error => {
|
|
|
+ downloadCalendarFailure: (error) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/DOWNLOAD_CALENDAR_FAILURE',
|
|
|
- error
|
|
|
+ error,
|
|
|
}
|
|
|
},
|
|
|
- parseCalendarRequest: data => {
|
|
|
+ parseCalendarRequest: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/PARSE_CALENDAR_REQUEST',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
- parseCalendarSuccess: data => {
|
|
|
+ parseCalendarSuccess: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/PARSE_CALENDAR_SUCCESS',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
- parseCalendarFailure: error => {
|
|
|
+ parseCalendarFailure: (error) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/PARSE_CALENDAR_FAILURE',
|
|
|
- error
|
|
|
+ error,
|
|
|
}
|
|
|
},
|
|
|
- deleteCalendarRequest: data => {
|
|
|
+ deleteCalendarRequest: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/DELETE_CALENDAR_REQUEST',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
- deleteCalendarSuccess: data => {
|
|
|
+ deleteCalendarSuccess: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/DELETE_CALENDAR_SUCCESS',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
- deleteCalendarFailure: error => {
|
|
|
+ deleteCalendarFailure: (error) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/DELETE_CALENDAR_FAILURE',
|
|
|
- error
|
|
|
+ error,
|
|
|
}
|
|
|
},
|
|
|
getPlayerListRequest: () => {
|
|
|
return {
|
|
|
- type: 'SWISSTENNIS/GET_PLAYERLIST_REQUEST'
|
|
|
+ type: 'SWISSTENNIS/GET_PLAYERLIST_REQUEST',
|
|
|
}
|
|
|
},
|
|
|
getPlayerListSuccess: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/GET_PLAYERLIST_SUCCESS',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
- getPlayerListFailure: error => {
|
|
|
+ getPlayerListFailure: (error) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/GET_PLAYERLIST_FAILURE',
|
|
|
- error
|
|
|
+ error,
|
|
|
}
|
|
|
},
|
|
|
getPlayerListsRequest: () => {
|
|
|
return {
|
|
|
- type: 'SWISSTENNIS/GET_PLAYERLISTS_REQUEST'
|
|
|
+ type: 'SWISSTENNIS/GET_PLAYERLISTS_REQUEST',
|
|
|
}
|
|
|
},
|
|
|
getPlayerListsSuccess: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/GET_PLAYERLISTS_SUCCESS',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
- getPlayerListsFailure: error => {
|
|
|
+ getPlayerListsFailure: (error) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/GET_PLAYERLISTS_FAILURE',
|
|
|
- error
|
|
|
+ error,
|
|
|
}
|
|
|
},
|
|
|
getCalendarRequest: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/GET_CALENDAR_REQUEST',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
getCalendarSuccess: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/GET_CALENDAR_SUCCESS',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
- getCalendarFailure: error => {
|
|
|
+ getCalendarFailure: (error) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/GET_CALENDAR_FAILURE',
|
|
|
- error
|
|
|
+ error,
|
|
|
}
|
|
|
},
|
|
|
getCalendarsRequest: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/GET_CALENDARS_REQUEST',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
getCalendarsSuccess: (data) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/GET_CALENDARS_SUCCESS',
|
|
|
- data
|
|
|
+ data,
|
|
|
}
|
|
|
},
|
|
|
- getCalendarsFailure: error => {
|
|
|
+ getCalendarsFailure: (error) => {
|
|
|
return {
|
|
|
type: 'SWISSTENNIS/GET_CALENDARS_FAILURE',
|
|
|
- error
|
|
|
+ error,
|
|
|
}
|
|
|
},
|
|
|
}
|
|
@@ -271,8 +271,9 @@ const emptyFilter = {
|
|
|
p_category: '',
|
|
|
p_ranking: '',
|
|
|
p_phone: '',
|
|
|
- p_junior: 'off',
|
|
|
- p_paid: 'off',
|
|
|
+ p_email: '',
|
|
|
+ p_junior: '-1',
|
|
|
+ p_paid: '-1',
|
|
|
p_matches: false,
|
|
|
}
|
|
|
|
|
@@ -301,7 +302,7 @@ export const state = {
|
|
|
console.log('State state', state)
|
|
|
|
|
|
/** reducer is called by the redux dispatcher and handles all component actions */
|
|
|
-export function reducer (state = [], action) {
|
|
|
+export function reducer(state = [], action) {
|
|
|
let index
|
|
|
switch (action.type) {
|
|
|
case 'SWISSTENNIS/SET_FILTER':
|
|
@@ -321,13 +322,22 @@ export function reducer (state = [], action) {
|
|
|
case 'SWISSTENNIS/FILE_LIST_FAILURE':
|
|
|
return { ...state, fileListStatus: 'failure' }
|
|
|
case 'SWISSTENNIS/LOGIN_REQUEST':
|
|
|
- return { ...state,
|
|
|
- loginStatus: 'request',
|
|
|
- playerListDownloadStatus: action.data.sequence ? 'uninitialized' : state.playerListDownloadStatus,
|
|
|
- playerListParseStatus: action.data.sequence ? 'uninitialized' : state.playerListParseStatus,
|
|
|
- calendarDownloadStatus: action.data.sequence ? 'uninitialized' : state.calendarDownloadStatus,
|
|
|
- calendarParseStatus: action.data.sequence ? 'uninitialized' : state.calendarParseStatus,
|
|
|
- }
|
|
|
+ return {
|
|
|
+ ...state,
|
|
|
+ loginStatus: 'request',
|
|
|
+ playerListDownloadStatus: action.data.sequence
|
|
|
+ ? 'uninitialized'
|
|
|
+ : state.playerListDownloadStatus,
|
|
|
+ playerListParseStatus: action.data.sequence
|
|
|
+ ? 'uninitialized'
|
|
|
+ : state.playerListParseStatus,
|
|
|
+ calendarDownloadStatus: action.data.sequence
|
|
|
+ ? 'uninitialized'
|
|
|
+ : state.calendarDownloadStatus,
|
|
|
+ calendarParseStatus: action.data.sequence
|
|
|
+ ? 'uninitialized'
|
|
|
+ : state.calendarParseStatus,
|
|
|
+ }
|
|
|
case 'SWISSTENNIS/LOGIN_SUCCESS':
|
|
|
return { ...state, loginStatus: 'success' }
|
|
|
case 'SWISSTENNIS/LOGIN_FAILURE':
|
|
@@ -335,39 +345,73 @@ export function reducer (state = [], action) {
|
|
|
case 'SWISSTENNIS/DOWNLOAD_PLAYERLIST_REQUEST':
|
|
|
return { ...state, playerListDownloadStatus: 'request' }
|
|
|
case 'SWISSTENNIS/DOWNLOAD_PLAYERLIST_SUCCESS':
|
|
|
- return { ...state, playerListDownloadStatus: 'success', files: [ ...state.files, action.data ] }
|
|
|
+ return {
|
|
|
+ ...state,
|
|
|
+ playerListDownloadStatus: 'success',
|
|
|
+ files: [...state.files, action.data],
|
|
|
+ }
|
|
|
case 'SWISSTENNIS/DOWNLOAD_PLAYERLIST_FAILURE':
|
|
|
return { ...state, playerListDownloadStatus: 'failure' }
|
|
|
case 'SWISSTENNIS/PARSE_PLAYERLIST_REQUEST':
|
|
|
return { ...state, playerListParseStatus: 'request' }
|
|
|
case 'SWISSTENNIS/PARSE_PLAYERLIST_SUCCESS':
|
|
|
- return { ...state, playerListParseStatus: 'success', playerLists: [ ...state.playerLists, action.data.playerList ] }
|
|
|
+ return {
|
|
|
+ ...state,
|
|
|
+ playerListParseStatus: 'success',
|
|
|
+ playerLists: [...state.playerLists, action.data.playerList],
|
|
|
+ }
|
|
|
case 'SWISSTENNIS/PARSE_PLAYERLIST_FAILURE':
|
|
|
return { ...state, playerListParseStatus: 'failure' }
|
|
|
case 'SWISSTENNIS/DELETE_PLAYERLIST_REQUEST':
|
|
|
return { ...state, playerListDeleteStatus: 'request' }
|
|
|
case 'SWISSTENNIS/DELETE_PLAYERLIST_SUCCESS':
|
|
|
- index = state.playerLists.findIndex(playerList => playerList._id === action.data._id)
|
|
|
- return { ...state, playerListDeleteStatus: 'success', playerLists: [ ...state.playerLists.slice(0, index), ...state.playerLists.slice(index + 1) ] }
|
|
|
+ index = state.playerLists.findIndex(
|
|
|
+ (playerList) => playerList._id === action.data._id
|
|
|
+ )
|
|
|
+ return {
|
|
|
+ ...state,
|
|
|
+ playerListDeleteStatus: 'success',
|
|
|
+ playerLists: [
|
|
|
+ ...state.playerLists.slice(0, index),
|
|
|
+ ...state.playerLists.slice(index + 1),
|
|
|
+ ],
|
|
|
+ }
|
|
|
case 'SWISSTENNIS/DELETE_PLAYERLIST_FAILURE':
|
|
|
return { ...state, playerListDeleteStatus: 'failure' }
|
|
|
case 'SWISSTENNIS/DOWNLOAD_CALENDAR_REQUEST':
|
|
|
return { ...state, calendarDownloadStatus: 'request' }
|
|
|
case 'SWISSTENNIS/DOWNLOAD_CALENDAR_SUCCESS':
|
|
|
- return { ...state, calendarDownloadStatus: 'success', files: [ ...state.files, action.data ] }
|
|
|
+ return {
|
|
|
+ ...state,
|
|
|
+ calendarDownloadStatus: 'success',
|
|
|
+ files: [...state.files, action.data],
|
|
|
+ }
|
|
|
case 'SWISSTENNIS/DOWNLOAD_CALENDAR_FAILURE':
|
|
|
return { ...state, calendarDownloadStatus: 'failure' }
|
|
|
case 'SWISSTENNIS/PARSE_CALENDAR_REQUEST':
|
|
|
return { ...state, calendarParseStatus: 'request' }
|
|
|
case 'SWISSTENNIS/PARSE_CALENDAR_SUCCESS':
|
|
|
- return { ...state, calendarParseStatus: 'success', calendars: [ ...state.calendars, action.data.matchList ] }
|
|
|
+ return {
|
|
|
+ ...state,
|
|
|
+ calendarParseStatus: 'success',
|
|
|
+ calendars: [...state.calendars, action.data.matchList],
|
|
|
+ }
|
|
|
case 'SWISSTENNIS/PARSE_CALENDAR_FAILURE':
|
|
|
return { ...state, calendarParseStatus: 'failure' }
|
|
|
case 'SWISSTENNIS/DELETE_CALENDAR_REQUEST':
|
|
|
return { ...state, calendarDeleteStatus: 'request' }
|
|
|
case 'SWISSTENNIS/DELETE_CALENDAR_SUCCESS':
|
|
|
- index = state.calendars.findIndex(calendar => calendar._id === action.data._id)
|
|
|
- return { ...state, calendarDeleteStatus: 'success', calendars: [ ...state.calendars.slice(0, index), ...state.calendars.slice(index + 1) ] }
|
|
|
+ index = state.calendars.findIndex(
|
|
|
+ (calendar) => calendar._id === action.data._id
|
|
|
+ )
|
|
|
+ return {
|
|
|
+ ...state,
|
|
|
+ calendarDeleteStatus: 'success',
|
|
|
+ calendars: [
|
|
|
+ ...state.calendars.slice(0, index),
|
|
|
+ ...state.calendars.slice(index + 1),
|
|
|
+ ],
|
|
|
+ }
|
|
|
case 'SWISSTENNIS/DELETE_CALENDAR_FAILURE':
|
|
|
return { ...state, calendarDeleteStatus: 'failure' }
|
|
|
case 'SWISSTENNIS/GET_CALENDAR_REQUEST':
|
|
@@ -399,52 +443,108 @@ export function reducer (state = [], action) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function * filterPlayers (action) {
|
|
|
+function* filterPlayers(action) {
|
|
|
const state = yield select()
|
|
|
const { playerList } = state.swisstennis
|
|
|
const filter = action.data
|
|
|
- const filteredPlayers = playerList ? playerList.players.filter(player => {
|
|
|
- return (
|
|
|
- (filter.p_name ? player.fullName && player.fullName.toLowerCase().includes(filter.p_name.toLowerCase()) : true) &&
|
|
|
- (filter.p_category ? player.category && player.category.toLowerCase().includes(filter.p_category.toLowerCase()) : true) &&
|
|
|
- (filter.p_ranking ? player.ranking && player.ranking.toLowerCase().includes(filter.p_ranking.toLowerCase()) : true) &&
|
|
|
- (filter.p_phone ? player.phone && player.phone.toLowerCase().includes(filter.p_phone.toLowerCase()) : true) &&
|
|
|
- /*(filter.p_junior !== 'off' ? player.junior === (filter.p_junior === 'Ja') : true) &&
|
|
|
- (filter.p_paid !== 'off' ? player.paid === (filter.p_paid === 'Ja') : true)*/ true
|
|
|
- )
|
|
|
- }) : []
|
|
|
- yield put(actions.filterPlayersDone({filteredPlayers}))
|
|
|
+ console.log('filter', filter)
|
|
|
+ const filteredPlayers = playerList
|
|
|
+ ? playerList.players.filter((player) => {
|
|
|
+ return (
|
|
|
+ (filter.p_name
|
|
|
+ ? player.fullName &&
|
|
|
+ player.fullName
|
|
|
+ .toLowerCase()
|
|
|
+ .includes(filter.p_name.toLowerCase())
|
|
|
+ : true) &&
|
|
|
+ (filter.p_category
|
|
|
+ ? player.category &&
|
|
|
+ player.category
|
|
|
+ .toLowerCase()
|
|
|
+ .includes(filter.p_category.toLowerCase())
|
|
|
+ : true) &&
|
|
|
+ (filter.p_ranking
|
|
|
+ ? player.ranking &&
|
|
|
+ player.ranking
|
|
|
+ .toLowerCase()
|
|
|
+ .includes(filter.p_ranking.toLowerCase())
|
|
|
+ : true) &&
|
|
|
+ (filter.p_phone
|
|
|
+ ? player.phone &&
|
|
|
+ player.phone.toLowerCase().includes(filter.p_phone.toLowerCase())
|
|
|
+ : true) &&
|
|
|
+ (filter.p_email
|
|
|
+ ? player.email &&
|
|
|
+ player.email.toLowerCase().includes(filter.p_email.toLowerCase())
|
|
|
+ : true) &&
|
|
|
+ (filter.p_junior === '-1'
|
|
|
+ ? true
|
|
|
+ : player.junior === (filter.p_junior === '1')) &&
|
|
|
+ (filter.p_paid === '-1'
|
|
|
+ ? true
|
|
|
+ : player.paid === (filter.p_paid === '1'))
|
|
|
+ )
|
|
|
+ })
|
|
|
+ : []
|
|
|
+ yield put(actions.filterPlayersDone({ filteredPlayers }))
|
|
|
}
|
|
|
|
|
|
-function * filterMatches (action) {
|
|
|
+function* filterMatches(action) {
|
|
|
const state = yield select()
|
|
|
const { calendar } = state.swisstennis
|
|
|
const filter = action.data
|
|
|
- const filteredMatches = calendar ? calendar.matches.filter(match => {
|
|
|
- return (
|
|
|
- (filter.m_category ? match.category && match.category.toLowerCase().includes(filter.m_category.toLowerCase()) : true) &&
|
|
|
- (filter.m_place ? match.place && match.place.toLowerCase().includes(filter.m_place.toLowerCase()) : true) &&
|
|
|
- (filter.m_date ? match.date && moment(match.date).format('DD.MM.YYYY').includes(filter.m_date) : true) &&
|
|
|
- (filter.m_time ? match.date && moment(match.date).format('HH:mm').includes(filter.m_time) : true) &&
|
|
|
- (filter.m_player ?
|
|
|
- (match.player1 && match.player1.fullName.toLowerCase().includes(filter.m_player.toLowerCase())) || (match.player2 && match.player2.fullName.toLowerCase().includes(filter.m_player.toLowerCase())) :
|
|
|
- true) &&
|
|
|
- (filter.m_result ? match.result.toLowerCase().includes(filter.m_result) : true)
|
|
|
- )
|
|
|
- }) : []
|
|
|
- yield put(actions.filterMatchesDone({filteredMatches}))
|
|
|
+ const filteredMatches = calendar
|
|
|
+ ? calendar.matches.filter((match) => {
|
|
|
+ return (
|
|
|
+ (filter.m_category
|
|
|
+ ? match.category &&
|
|
|
+ match.category
|
|
|
+ .toLowerCase()
|
|
|
+ .includes(filter.m_category.toLowerCase())
|
|
|
+ : true) &&
|
|
|
+ (filter.m_place
|
|
|
+ ? match.place &&
|
|
|
+ match.place.toLowerCase().includes(filter.m_place.toLowerCase())
|
|
|
+ : true) &&
|
|
|
+ (filter.m_date
|
|
|
+ ? match.date &&
|
|
|
+ moment(match.date).format('DD.MM.YYYY').includes(filter.m_date)
|
|
|
+ : true) &&
|
|
|
+ (filter.m_time
|
|
|
+ ? match.date &&
|
|
|
+ moment(match.date).format('HH:mm').includes(filter.m_time)
|
|
|
+ : true) &&
|
|
|
+ (filter.m_player
|
|
|
+ ? (match.player1 &&
|
|
|
+ match.player1.fullName
|
|
|
+ .toLowerCase()
|
|
|
+ .includes(filter.m_player.toLowerCase())) ||
|
|
|
+ (match.player2 &&
|
|
|
+ match.player2.fullName
|
|
|
+ .toLowerCase()
|
|
|
+ .includes(filter.m_player.toLowerCase()))
|
|
|
+ : true) &&
|
|
|
+ (filter.m_result
|
|
|
+ ? match.result.toLowerCase().includes(filter.m_result)
|
|
|
+ : true)
|
|
|
+ )
|
|
|
+ })
|
|
|
+ : []
|
|
|
+ yield put(actions.filterMatchesDone({ filteredMatches }))
|
|
|
}
|
|
|
|
|
|
-function * fileList (action) {
|
|
|
- yield put(api.actions.apiRequest({
|
|
|
- path: `api/swisstennis/files`,
|
|
|
- method: 'GET',
|
|
|
- onSuccess: actions.fileListSuccess,
|
|
|
- onFailure: actions.fileListFailure
|
|
|
- }))
|
|
|
+function* fileList(action) {
|
|
|
+ yield put(
|
|
|
+ api.actions.apiRequest({
|
|
|
+ path: `api/swisstennis/files`,
|
|
|
+ method: 'GET',
|
|
|
+ onSuccess: actions.fileListSuccess,
|
|
|
+ onFailure: actions.fileListFailure,
|
|
|
+ })
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
-function * login (action) {
|
|
|
+function* login(action) {
|
|
|
try {
|
|
|
const token = localStorage.getItem('accessToken')
|
|
|
console.log('Swisstennis login requested', action, token)
|
|
@@ -452,16 +552,17 @@ function * login (action) {
|
|
|
method: 'POST',
|
|
|
headers: {
|
|
|
'Content-Type': 'application/json',
|
|
|
- 'x-access-token': token
|
|
|
- }
|
|
|
- })
|
|
|
+ 'x-access-token': token,
|
|
|
+ },
|
|
|
+ })
|
|
|
if (response.status !== 200) {
|
|
|
console.log(response)
|
|
|
throw Error(response.status)
|
|
|
} else {
|
|
|
const responseJson = yield response.json()
|
|
|
yield put(actions.loginSuccess(responseJson))
|
|
|
- if (action.data.sequence) yield put(actions.downloadPlayerListRequest({sequence: true}))
|
|
|
+ if (action.data.sequence)
|
|
|
+ yield put(actions.downloadPlayerListRequest({ sequence: true }))
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.log('Config failure!', actions.loginFailure(error))
|
|
@@ -469,41 +570,59 @@ function * login (action) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function * getCalendars (action) {
|
|
|
- yield put(api.actions.apiRequest({
|
|
|
- path: `api/swisstennis/calendars`,
|
|
|
- method: 'GET',
|
|
|
- onSuccess: actions.getCalendarsSuccess,
|
|
|
- onFailure: actions.getCalendarsFailure
|
|
|
- }))
|
|
|
+function* getCalendars(action) {
|
|
|
+ yield put(
|
|
|
+ api.actions.apiRequest({
|
|
|
+ path: `api/swisstennis/calendars`,
|
|
|
+ method: 'GET',
|
|
|
+ onSuccess: actions.getCalendarsSuccess,
|
|
|
+ onFailure: actions.getCalendarsFailure,
|
|
|
+ })
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
-function * getCalendar (action) {
|
|
|
- yield put(api.actions.apiRequest({
|
|
|
- path: `api/swisstennis/calendar${(action.data && action.data.calendarId) ? `?calendarId=${action.data.calendarId}` : ''}`,
|
|
|
- method: 'GET',
|
|
|
- onSuccess: [actions.getCalendarSuccess, actions.filterMatches],
|
|
|
- onFailure: actions.getCalendarFailure
|
|
|
- }))
|
|
|
+function* getCalendar(action) {
|
|
|
+ yield put(
|
|
|
+ api.actions.apiRequest({
|
|
|
+ path: `api/swisstennis/calendar${
|
|
|
+ action.data && action.data.calendarId
|
|
|
+ ? `?calendarId=${action.data.calendarId}`
|
|
|
+ : ''
|
|
|
+ }`,
|
|
|
+ method: 'GET',
|
|
|
+ onSuccess: [actions.getCalendarSuccess, actions.filterMatches],
|
|
|
+ onFailure: actions.getCalendarFailure,
|
|
|
+ })
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
-function * downloadCalendar (action) {
|
|
|
+function* downloadCalendar(action) {
|
|
|
try {
|
|
|
const token = localStorage.getItem('accessToken')
|
|
|
console.log('Download calendar requested', action, token)
|
|
|
- const response = yield call(fetch, `${SZTM_API}/api/swisstennis/calendar/download`, {
|
|
|
- method: 'GET',
|
|
|
- headers: {
|
|
|
- 'Content-Type': 'application/json',
|
|
|
- 'x-access-token': token
|
|
|
+ const response = yield call(
|
|
|
+ fetch,
|
|
|
+ `${SZTM_API}/api/swisstennis/calendar/download`,
|
|
|
+ {
|
|
|
+ method: 'GET',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ 'x-access-token': token,
|
|
|
+ },
|
|
|
}
|
|
|
- })
|
|
|
+ )
|
|
|
if (response.status !== 200) {
|
|
|
throw Error(response.status)
|
|
|
} else {
|
|
|
const responseJson = yield response.json()
|
|
|
yield put(actions.downloadCalendarSuccess(responseJson))
|
|
|
- if (action.data.sequence) yield put(actions.parseCalendarRequest({filename: responseJson.filename, sequence: true}))
|
|
|
+ if (action.data.sequence)
|
|
|
+ yield put(
|
|
|
+ actions.parseCalendarRequest({
|
|
|
+ filename: responseJson.filename,
|
|
|
+ sequence: true,
|
|
|
+ })
|
|
|
+ )
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.log('Config failure!', actions.downloadCalendarFailure(error))
|
|
@@ -511,58 +630,80 @@ function * downloadCalendar (action) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function * parseCalendar (action) {
|
|
|
- yield put(api.actions.apiRequest({
|
|
|
- path: `api/swisstennis/calendar/parse/${action.data.filename}`,
|
|
|
- method: 'GET',
|
|
|
- onSuccess: actions.parseCalendarSuccess,
|
|
|
- onFailure: actions.parseCalendarFailure
|
|
|
- }))
|
|
|
+function* parseCalendar(action) {
|
|
|
+ yield put(
|
|
|
+ api.actions.apiRequest({
|
|
|
+ path: `api/swisstennis/calendar/parse/${action.data.filename}`,
|
|
|
+ method: 'GET',
|
|
|
+ onSuccess: actions.parseCalendarSuccess,
|
|
|
+ onFailure: actions.parseCalendarFailure,
|
|
|
+ })
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
-function * deleteCalendar (action) {
|
|
|
- yield put(api.actions.apiRequest({
|
|
|
- path: `api/swisstennis/calendar/${action.data.calendarId}`,
|
|
|
- method: 'DELETE',
|
|
|
- onSuccess: actions.deleteCalendarSuccess,
|
|
|
- onFailure: actions.deleteCalendarFailure
|
|
|
- }))
|
|
|
+function* deleteCalendar(action) {
|
|
|
+ yield put(
|
|
|
+ api.actions.apiRequest({
|
|
|
+ path: `api/swisstennis/calendar/${action.data.calendarId}`,
|
|
|
+ method: 'DELETE',
|
|
|
+ onSuccess: actions.deleteCalendarSuccess,
|
|
|
+ onFailure: actions.deleteCalendarFailure,
|
|
|
+ })
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
-function * getPlayerLists (action) {
|
|
|
- yield put(api.actions.apiRequest({
|
|
|
- path: `api/swisstennis/playerlists`,
|
|
|
- method: 'GET',
|
|
|
- onSuccess: actions.getPlayerListsSuccess,
|
|
|
- onFailure: actions.getPlayerListsFailure
|
|
|
- }))
|
|
|
+function* getPlayerLists(action) {
|
|
|
+ yield put(
|
|
|
+ api.actions.apiRequest({
|
|
|
+ path: `api/swisstennis/playerlists`,
|
|
|
+ method: 'GET',
|
|
|
+ onSuccess: actions.getPlayerListsSuccess,
|
|
|
+ onFailure: actions.getPlayerListsFailure,
|
|
|
+ })
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
-function * getPlayerList (action) {
|
|
|
- yield put(api.actions.apiRequest({
|
|
|
- path: `api/swisstennis/playerlist${(action.data && action.data.playerlistId) ? `?playerlistId=${action.data.playerlistId}` : ''}`,
|
|
|
- method: 'GET',
|
|
|
- onSuccess: [actions.getPlayerListSuccess, actions.filterPlayers],
|
|
|
- onFailure: actions.getPlayerListFailure
|
|
|
- }))
|
|
|
+function* getPlayerList(action) {
|
|
|
+ yield put(
|
|
|
+ api.actions.apiRequest({
|
|
|
+ path: `api/swisstennis/playerlist${
|
|
|
+ action.data && action.data.playerlistId
|
|
|
+ ? `?playerlistId=${action.data.playerlistId}`
|
|
|
+ : ''
|
|
|
+ }`,
|
|
|
+ method: 'GET',
|
|
|
+ onSuccess: [actions.getPlayerListSuccess, actions.filterPlayers],
|
|
|
+ onFailure: actions.getPlayerListFailure,
|
|
|
+ })
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
-function * downloadPlayerList (action) {
|
|
|
+function* downloadPlayerList(action) {
|
|
|
try {
|
|
|
const token = localStorage.getItem('accessToken')
|
|
|
console.log('Playerlist download requested', action, token)
|
|
|
- const response = yield call(fetch, `${SZTM_API}/api/swisstennis/playerlist/download`, {
|
|
|
- method: 'GET',
|
|
|
- headers: {
|
|
|
- 'x-access-token': token
|
|
|
+ const response = yield call(
|
|
|
+ fetch,
|
|
|
+ `${SZTM_API}/api/swisstennis/playerlist/download`,
|
|
|
+ {
|
|
|
+ method: 'GET',
|
|
|
+ headers: {
|
|
|
+ 'x-access-token': token,
|
|
|
+ },
|
|
|
}
|
|
|
- })
|
|
|
+ )
|
|
|
if (response.status !== 200) {
|
|
|
throw Error(response.status)
|
|
|
} else {
|
|
|
const responseJson = yield response.json()
|
|
|
yield put(actions.downloadPlayerListSuccess(responseJson))
|
|
|
- if (action.data.sequence) yield put(actions.parsePlayerListRequest({filename: responseJson.filename, sequence: true}))
|
|
|
+ if (action.data.sequence)
|
|
|
+ yield put(
|
|
|
+ actions.parsePlayerListRequest({
|
|
|
+ filename: responseJson.filename,
|
|
|
+ sequence: true,
|
|
|
+ })
|
|
|
+ )
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.log('Config failure!', actions.downloadPlayerListFailure(error))
|
|
@@ -570,22 +711,27 @@ function * downloadPlayerList (action) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function * parsePlayerList (action) {
|
|
|
+function* parsePlayerList(action) {
|
|
|
try {
|
|
|
const token = localStorage.getItem('accessToken')
|
|
|
console.log('PlayerList parse requested', action, token)
|
|
|
- const response = yield call(fetch, `${SZTM_API}/api/swisstennis/playerlist/parse/${action.data.filename}`, {
|
|
|
- method: 'GET',
|
|
|
- headers: {
|
|
|
- 'x-access-token': token
|
|
|
+ const response = yield call(
|
|
|
+ fetch,
|
|
|
+ `${SZTM_API}/api/swisstennis/playerlist/parse/${action.data.filename}`,
|
|
|
+ {
|
|
|
+ method: 'GET',
|
|
|
+ headers: {
|
|
|
+ 'x-access-token': token,
|
|
|
+ },
|
|
|
}
|
|
|
- })
|
|
|
+ )
|
|
|
if (response.status !== 200) {
|
|
|
throw Error(response.status)
|
|
|
} else {
|
|
|
const responseJson = yield response.json()
|
|
|
yield put(actions.parsePlayerListSuccess(responseJson))
|
|
|
- if (action.data.sequence) yield put(actions.downloadCalendarRequest({sequence: true}))
|
|
|
+ if (action.data.sequence)
|
|
|
+ yield put(actions.downloadCalendarRequest({ sequence: true }))
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.log('Config failure!', actions.parsePlayerListFailure(error))
|
|
@@ -593,17 +739,19 @@ function * parsePlayerList (action) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function * deletePlayerList (action) {
|
|
|
- yield put(api.actions.apiRequest({
|
|
|
- path: `api/swisstennis/playerlist/${action.data.playerlistId}`,
|
|
|
- method: 'DELETE',
|
|
|
- onSuccess: actions.deletePlayerListSuccess,
|
|
|
- onFailure: actions.deletePlayerListFailure
|
|
|
- }))
|
|
|
+function* deletePlayerList(action) {
|
|
|
+ yield put(
|
|
|
+ api.actions.apiRequest({
|
|
|
+ path: `api/swisstennis/playerlist/${action.data.playerlistId}`,
|
|
|
+ method: 'DELETE',
|
|
|
+ onSuccess: actions.deletePlayerListSuccess,
|
|
|
+ onFailure: actions.deletePlayerListFailure,
|
|
|
+ })
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
/** sagas are asynchronous workers (JS generators) to handle the state. */
|
|
|
-export function * saga () {
|
|
|
+export function* saga() {
|
|
|
console.log('Config saga started.')
|
|
|
yield takeEvery('SWISSTENNIS/FILE_LIST_REQUEST', fileList)
|
|
|
yield takeEvery('SWISSTENNIS/DOWNLOAD_PLAYERLIST_REQUEST', downloadPlayerList)
|