lbry-desktop/ui/js/reducers/claims.js

100 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-06-06 23:19:12 +02:00
import * as types from "constants/action_types";
import lbryuri from "lbryuri";
2017-04-28 17:14:44 +02:00
2017-06-06 06:21:55 +02:00
const reducers = {};
const defaultState = {};
2017-04-28 17:14:44 +02:00
reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) {
2017-06-06 23:19:12 +02:00
const { uri, certificate, claim } = action.data;
2017-04-28 17:14:44 +02:00
2017-06-06 23:19:12 +02:00
const newClaims = Object.assign({}, state.claimsByUri);
2017-05-13 00:50:51 +02:00
2017-06-06 23:19:12 +02:00
newClaims[uri] = claim;
2017-05-13 00:50:51 +02:00
//This needs a sanity boost...
2017-05-15 05:50:59 +02:00
if (certificate !== undefined && claim === undefined) {
const uriParts = lbryuri.parse(uri);
// newChannelClaims[uri] = certificate
2017-05-13 00:50:51 +02:00
if (claim === undefined) {
2017-06-06 23:19:12 +02:00
newClaims[uri] = certificate;
2017-05-13 00:50:51 +02:00
}
}
return Object.assign({}, state, {
2017-06-06 23:19:12 +02:00
claimsByUri: newClaims,
});
2017-06-06 06:21:55 +02:00
};
2017-05-13 00:50:51 +02:00
reducers[types.RESOLVE_URI_CANCELED] = function(state, action) {
2017-06-06 23:19:12 +02:00
const uri = action.data.uri;
const newClaims = Object.assign({}, state.claimsByUri);
delete newClaims[uri];
return Object.assign({}, state, {
2017-06-06 23:19:12 +02:00
claimsByUri: newClaims,
});
2017-06-06 06:21:55 +02:00
};
reducers[types.FETCH_CLAIM_LIST_MINE_STARTED] = function(state, action) {
return Object.assign({}, state, {
2017-06-06 23:19:12 +02:00
isClaimListMinePending: true,
});
2017-06-06 06:21:55 +02:00
};
reducers[types.FETCH_CLAIM_LIST_MINE_COMPLETED] = function(state, action) {
2017-06-06 23:19:12 +02:00
const { claims } = action.data;
const myClaims = new Set(state.myClaims);
const byUri = Object.assign({}, state.claimsByUri);
claims.forEach(claim => {
const uri = lbryuri.build({
contentName: claim.name,
claimId: claim.claim_id,
claimSequence: claim.nout,
2017-06-06 23:19:12 +02:00
});
myClaims.add(uri);
byUri[uri] = claim;
});
return Object.assign({}, state, {
isClaimListMinePending: false,
myClaims: myClaims,
claimsByUri: byUri,
2017-06-06 23:19:12 +02:00
});
2017-06-06 06:21:55 +02:00
};
2017-05-21 16:42:34 +02:00
// reducers[types.FETCH_CHANNEL_CLAIMS_STARTED] = function(state, action) {
// const {
// uri,
// } = action.data
//
// const newClaims = Object.assign({}, state.claimsByChannel)
//
// if (claims !== undefined) {
// newClaims[uri] = claims
// }
//
// return Object.assign({}, state, {
// claimsByChannel: newClaims
// })
// }
2017-05-13 00:50:51 +02:00
reducers[types.FETCH_CHANNEL_CLAIMS_COMPLETED] = function(state, action) {
2017-06-06 23:19:12 +02:00
const { uri, claims } = action.data;
2017-05-13 00:50:51 +02:00
2017-06-06 23:19:12 +02:00
const newClaims = Object.assign({}, state.claimsByChannel);
2017-05-13 00:50:51 +02:00
if (claims !== undefined) {
2017-06-06 23:19:12 +02:00
newClaims[uri] = claims;
2017-05-13 00:50:51 +02:00
}
2017-04-28 17:14:44 +02:00
return Object.assign({}, state, {
2017-06-06 23:19:12 +02:00
claimsByChannel: newClaims,
});
2017-06-06 06:21:55 +02:00
};
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;
}