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;
|
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 || {};
|
const selectState$2 = state => state.claims || {};
|
||||||
|
@ -3617,6 +3635,7 @@ const defaultState = {
|
||||||
// This should not be a Set
|
// This should not be a Set
|
||||||
// Storing sets in reducers can cause issues
|
// Storing sets in reducers can cause issues
|
||||||
myChannelClaims: undefined,
|
myChannelClaims: undefined,
|
||||||
|
myClaims: undefined,
|
||||||
fetchingMyChannels: false,
|
fetchingMyChannels: false,
|
||||||
abandoningById: {},
|
abandoningById: {},
|
||||||
pendingById: {},
|
pendingById: {},
|
||||||
|
@ -3713,6 +3732,7 @@ reducers[FETCH_CLAIM_LIST_MINE_COMPLETED] = (state, action) => {
|
||||||
const byId = Object.assign({}, state.byId);
|
const byId = Object.assign({}, state.byId);
|
||||||
const byUri = Object.assign({}, state.claimsByUri);
|
const byUri = Object.assign({}, state.claimsByUri);
|
||||||
const pendingById = Object.assign({}, state.pendingById);
|
const pendingById = Object.assign({}, state.pendingById);
|
||||||
|
const myClaims = state.myClaims || [];
|
||||||
|
|
||||||
claims.forEach(claim => {
|
claims.forEach(claim => {
|
||||||
const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id });
|
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, {
|
return Object.assign({}, state, {
|
||||||
isFetchingClaimListMine: false,
|
isFetchingClaimListMine: false,
|
||||||
myClaims: claims,
|
myClaims: concatClaims(myClaims, claims),
|
||||||
byId,
|
byId,
|
||||||
claimsByUri: byUri,
|
claimsByUri: byUri,
|
||||||
pendingById
|
pendingById
|
||||||
|
@ -3750,6 +3770,7 @@ reducers[FETCH_CHANNEL_LIST_STARTED] = state => Object.assign({}, state, { fetch
|
||||||
|
|
||||||
reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => {
|
reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => {
|
||||||
const { claims } = action.data;
|
const { claims } = action.data;
|
||||||
|
const myClaims = state.myClaims || [];
|
||||||
|
|
||||||
let myChannelClaims;
|
let myChannelClaims;
|
||||||
let byId = Object.assign({}, state.byId);
|
let byId = Object.assign({}, state.byId);
|
||||||
|
@ -3769,7 +3790,7 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => {
|
||||||
byId,
|
byId,
|
||||||
fetchingMyChannels: false,
|
fetchingMyChannels: false,
|
||||||
myChannelClaims,
|
myChannelClaims,
|
||||||
myClaims: claims
|
myClaims: concatClaims(myClaims, claims)
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
import * as ACTIONS from 'constants/action_types';
|
import * as ACTIONS from 'constants/action_types';
|
||||||
import { buildURI, parseURI } from 'lbryURI';
|
import { buildURI, parseURI } from 'lbryURI';
|
||||||
|
import { concatClaims } from 'util/claim';
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
createChannelError: ?string,
|
createChannelError: ?string,
|
||||||
|
@ -18,6 +19,7 @@ type State = {
|
||||||
byId: { [string]: Claim },
|
byId: { [string]: Claim },
|
||||||
resolvingUris: Array<string>,
|
resolvingUris: Array<string>,
|
||||||
pendingById: { [string]: Claim },
|
pendingById: { [string]: Claim },
|
||||||
|
myClaims: ?Array<Claim>,
|
||||||
myChannelClaims: ?Set<string>,
|
myChannelClaims: ?Set<string>,
|
||||||
abandoningById: { [string]: boolean },
|
abandoningById: { [string]: boolean },
|
||||||
fetchingChannelClaims: { [string]: number },
|
fetchingChannelClaims: { [string]: number },
|
||||||
|
@ -48,6 +50,7 @@ const defaultState = {
|
||||||
// This should not be a Set
|
// This should not be a Set
|
||||||
// Storing sets in reducers can cause issues
|
// Storing sets in reducers can cause issues
|
||||||
myChannelClaims: undefined,
|
myChannelClaims: undefined,
|
||||||
|
myClaims: undefined,
|
||||||
fetchingMyChannels: false,
|
fetchingMyChannels: false,
|
||||||
abandoningById: {},
|
abandoningById: {},
|
||||||
pendingById: {},
|
pendingById: {},
|
||||||
|
@ -153,6 +156,7 @@ reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED] = (state: State, action: any):
|
||||||
const byId = Object.assign({}, state.byId);
|
const byId = Object.assign({}, state.byId);
|
||||||
const byUri = Object.assign({}, state.claimsByUri);
|
const byUri = Object.assign({}, state.claimsByUri);
|
||||||
const pendingById: { [string]: Claim } = Object.assign({}, state.pendingById);
|
const pendingById: { [string]: Claim } = Object.assign({}, state.pendingById);
|
||||||
|
const myClaims = state.myClaims || [];
|
||||||
|
|
||||||
claims.forEach((claim: Claim) => {
|
claims.forEach((claim: Claim) => {
|
||||||
const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id });
|
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, {
|
return Object.assign({}, state, {
|
||||||
isFetchingClaimListMine: false,
|
isFetchingClaimListMine: false,
|
||||||
myClaims: claims,
|
myClaims: concatClaims(myClaims, claims),
|
||||||
byId,
|
byId,
|
||||||
claimsByUri: byUri,
|
claimsByUri: byUri,
|
||||||
pendingById,
|
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 => {
|
reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): State => {
|
||||||
const { claims }: { claims: Array<ChannelClaim> } = action.data;
|
const { claims }: { claims: Array<ChannelClaim> } = action.data;
|
||||||
|
const myClaims = state.myClaims || [];
|
||||||
|
|
||||||
let myChannelClaims;
|
let myChannelClaims;
|
||||||
let byId = Object.assign({}, state.byId);
|
let byId = Object.assign({}, state.byId);
|
||||||
|
@ -211,7 +216,7 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St
|
||||||
byId,
|
byId,
|
||||||
fetchingMyChannels: false,
|
fetchingMyChannels: false,
|
||||||
myChannelClaims,
|
myChannelClaims,
|
||||||
myClaims: claims,
|
myClaims: concatClaims(myClaims, claims),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,3 +30,21 @@ export function createNormalizedClaimSearchKey(options: { page?: number, release
|
||||||
const query = JSON.stringify(rest);
|
const query = JSON.stringify(rest);
|
||||||
return query;
|
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
Add a link
Reference in a new issue