|
|
|
@ -6,37 +6,45 @@ import {
|
|
|
|
|
|
|
|
|
|
const fareRuleInitState = { |
|
|
|
|
results: [], |
|
|
|
|
previous: null, |
|
|
|
|
next: null, |
|
|
|
|
count: 0, |
|
|
|
|
fetching: false, |
|
|
|
|
query: '', |
|
|
|
|
isNext: false, |
|
|
|
|
} |
|
|
|
|
const fareRule = (state = fareRuleInitState, action) => { |
|
|
|
|
switch(action.type) { |
|
|
|
|
case FARERULE_REQUEST: |
|
|
|
|
let resetResult, resetCount |
|
|
|
|
let resetResult, resetCount, isNextReq = false |
|
|
|
|
if (action.meta !== undefined) { |
|
|
|
|
if (action.meta.query === 'next') { |
|
|
|
|
isNextReq = true |
|
|
|
|
} else { |
|
|
|
|
resetResult = state.query !== action.meta.query ? [] : state.results |
|
|
|
|
resetCount = state.query !== action.meta.query ? 0 : state.count |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
const updateQRC = (action.meta !== undefined) && !isNextReq |
|
|
|
|
return { |
|
|
|
|
...state, |
|
|
|
|
fetching: true, |
|
|
|
|
query: action.meta !== undefined ? action.meta.query : state.query, |
|
|
|
|
results: action.meta !== undefined ? resetResult : state.results, |
|
|
|
|
count: action.meta !== undefined ? resetCount : state.count, |
|
|
|
|
query: updateQRC ? action.meta.query : state.query, |
|
|
|
|
results: updateQRC ? resetResult : state.results, |
|
|
|
|
count: updateQRC ? resetCount : state.count, |
|
|
|
|
} |
|
|
|
|
case FARERULE_SUCCESS: |
|
|
|
|
const { count, next, prev, results } = action.payload |
|
|
|
|
const { count, next, previous, results } = action.payload |
|
|
|
|
return { |
|
|
|
|
...state, |
|
|
|
|
fetching: false, |
|
|
|
|
count, |
|
|
|
|
previous, |
|
|
|
|
next, |
|
|
|
|
results: [ |
|
|
|
|
...( (prev) ? state.results : [] ), |
|
|
|
|
...( (previous) ? state.results : [] ), |
|
|
|
|
...results, |
|
|
|
|
] |
|
|
|
|
], |
|
|
|
|
} |
|
|
|
|
case FARERULE_UPDATE: |
|
|
|
|
const { id } = action.payload |
|
|
|
|