2017-04-28 17:14:44 +02:00
|
|
|
import * as types from 'constants/action_types'
|
2017-04-29 11:50:29 +02:00
|
|
|
import lbryuri from 'lbryuri'
|
2017-04-28 17:14:44 +02:00
|
|
|
|
|
|
|
const reducers = {}
|
|
|
|
const defaultState = {
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) {
|
|
|
|
const {
|
|
|
|
uri,
|
|
|
|
claim,
|
|
|
|
} = action.data
|
|
|
|
const newByUri = Object.assign({}, state.byUri)
|
|
|
|
|
|
|
|
newByUri[uri] = claim
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
byUri: newByUri,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-05-01 08:26:09 +02:00
|
|
|
reducers[types.FETCH_MY_CLAIMS_COMPLETED] = function(state, action) {
|
|
|
|
const {
|
|
|
|
claims,
|
|
|
|
} = action.data
|
|
|
|
const newMine = Object.assign({}, state.mine)
|
|
|
|
const newById = Object.assign({}, newMine.byId)
|
|
|
|
|
|
|
|
claims.forEach(claim => {
|
|
|
|
newById[claim.claim_id] = claim
|
|
|
|
})
|
|
|
|
newMine.byId = newById
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
mine: newMine,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-28 17:14:44 +02:00
|
|
|
export default function reducer(state = defaultState, action) {
|
|
|
|
const handler = reducers[action.type];
|
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|