concatenate unique claims after fetching owned claims or channel list
This commit is contained in:
parent
d44cd9ca56
commit
3fdec3cb62
3 changed files with 48 additions and 4 deletions
25
dist/bundle.es.js
vendored
25
dist/bundle.es.js
vendored
|
@ -1467,6 +1467,24 @@ function createNormalizedClaimSearchKey(options) {
|
|||
return query;
|
||||
}
|
||||
|
||||
function concatClaims(claimList = [], concatClaimList = []) {
|
||||
if (!claimList || claimList.length === 0) {
|
||||
if (!concatClaimList) {
|
||||
return [];
|
||||
}
|
||||
return concatClaimList.slice();
|
||||
}
|
||||
|
||||
const claims = claimList.slice();
|
||||
concatClaimList.forEach(claim => {
|
||||
if (!claims.some(item => item.claim_id === claim.claim_id)) {
|
||||
claims.push(claim);
|
||||
}
|
||||
});
|
||||
|
||||
return claims;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
const selectState$2 = state => state.claims || {};
|
||||
|
@ -3617,6 +3635,7 @@ const defaultState = {
|
|||
// This should not be a Set
|
||||
// Storing sets in reducers can cause issues
|
||||
myChannelClaims: undefined,
|
||||
myClaims: undefined,
|
||||
fetchingMyChannels: false,
|
||||
abandoningById: {},
|
||||
pendingById: {},
|
||||
|
@ -3713,6 +3732,7 @@ reducers[FETCH_CLAIM_LIST_MINE_COMPLETED] = (state, action) => {
|
|||
const byId = Object.assign({}, state.byId);
|
||||
const byUri = Object.assign({}, state.claimsByUri);
|
||||
const pendingById = Object.assign({}, state.pendingById);
|
||||
const myClaims = state.myClaims || [];
|
||||
|
||||
claims.forEach(claim => {
|
||||
const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id });
|
||||
|
@ -3739,7 +3759,7 @@ reducers[FETCH_CLAIM_LIST_MINE_COMPLETED] = (state, action) => {
|
|||
|
||||
return Object.assign({}, state, {
|
||||
isFetchingClaimListMine: false,
|
||||
myClaims: claims,
|
||||
myClaims: concatClaims(myClaims, claims),
|
||||
byId,
|
||||
claimsByUri: byUri,
|
||||
pendingById
|
||||
|
@ -3750,6 +3770,7 @@ reducers[FETCH_CHANNEL_LIST_STARTED] = state => Object.assign({}, state, { fetch
|
|||
|
||||
reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => {
|
||||
const { claims } = action.data;
|
||||
const myClaims = state.myClaims || [];
|
||||
|
||||
let myChannelClaims;
|
||||
let byId = Object.assign({}, state.byId);
|
||||
|
@ -3769,7 +3790,7 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => {
|
|||
byId,
|
||||
fetchingMyChannels: false,
|
||||
myChannelClaims,
|
||||
myClaims: claims
|
||||
myClaims: concatClaims(myClaims, claims)
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
import * as ACTIONS from 'constants/action_types';
|
||||
import { buildURI, parseURI } from 'lbryURI';
|
||||
import { concatClaims } from 'util/claim';
|
||||
|
||||
type State = {
|
||||
createChannelError: ?string,
|
||||
|
@ -18,6 +19,7 @@ type State = {
|
|||
byId: { [string]: Claim },
|
||||
resolvingUris: Array<string>,
|
||||
pendingById: { [string]: Claim },
|
||||
myClaims: ?Array<Claim>,
|
||||
myChannelClaims: ?Set<string>,
|
||||
abandoningById: { [string]: boolean },
|
||||
fetchingChannelClaims: { [string]: number },
|
||||
|
@ -48,6 +50,7 @@ const defaultState = {
|
|||
// This should not be a Set
|
||||
// Storing sets in reducers can cause issues
|
||||
myChannelClaims: undefined,
|
||||
myClaims: undefined,
|
||||
fetchingMyChannels: false,
|
||||
abandoningById: {},
|
||||
pendingById: {},
|
||||
|
@ -153,6 +156,7 @@ reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED] = (state: State, action: any):
|
|||
const byId = Object.assign({}, state.byId);
|
||||
const byUri = Object.assign({}, state.claimsByUri);
|
||||
const pendingById: { [string]: Claim } = Object.assign({}, state.pendingById);
|
||||
const myClaims = state.myClaims || [];
|
||||
|
||||
claims.forEach((claim: Claim) => {
|
||||
const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id });
|
||||
|
@ -180,7 +184,7 @@ reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED] = (state: State, action: any):
|
|||
|
||||
return Object.assign({}, state, {
|
||||
isFetchingClaimListMine: false,
|
||||
myClaims: claims,
|
||||
myClaims: concatClaims(myClaims, claims),
|
||||
byId,
|
||||
claimsByUri: byUri,
|
||||
pendingById,
|
||||
|
@ -192,6 +196,7 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_STARTED] = (state: State): State =>
|
|||
|
||||
reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): State => {
|
||||
const { claims }: { claims: Array<ChannelClaim> } = action.data;
|
||||
const myClaims = state.myClaims || [];
|
||||
|
||||
let myChannelClaims;
|
||||
let byId = Object.assign({}, state.byId);
|
||||
|
@ -211,7 +216,7 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St
|
|||
byId,
|
||||
fetchingMyChannels: false,
|
||||
myChannelClaims,
|
||||
myClaims: claims,
|
||||
myClaims: concatClaims(myClaims, claims),
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -30,3 +30,21 @@ export function createNormalizedClaimSearchKey(options: { page?: number, release
|
|||
const query = JSON.stringify(rest);
|
||||
return query;
|
||||
}
|
||||
|
||||
export function concatClaims(claimList: Array<Claim> = [], concatClaimList: Array<any> = []): Array<Claim> {
|
||||
if (!claimList || claimList.length === 0) {
|
||||
if (!concatClaimList) {
|
||||
return [];
|
||||
}
|
||||
return concatClaimList.slice();
|
||||
}
|
||||
|
||||
const claims = claimList.slice();
|
||||
concatClaimList.forEach(claim => {
|
||||
if (!claims.some(item => item.claim_id === claim.claim_id)) {
|
||||
claims.push(claim);
|
||||
}
|
||||
});
|
||||
|
||||
return claims;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue