Collections #383

Merged
jessopb merged 20 commits from collections into master 2021-06-08 17:51:49 +02:00
6 changed files with 78 additions and 15 deletions
Showing only changes of commit 15eebee694 - Show all commits

44
dist/bundle.es.js vendored
View file

@ -3706,6 +3706,13 @@ const makeSelectNameForCollectionId = id => reselect.createSelector(makeSelectCo
return collection && collection.name || '';
});
const makeSelectCountForCollectionId = id => reselect.createSelector(makeSelectCollectionForId(id), collection => {
if (collection.itemCount !== undefined) {
return collection.itemCount;
}
return collection.items.length;
});
var _extends$5 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _asyncToGenerator$1(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
@ -4242,7 +4249,7 @@ function doFetchCollectionListMine(page = 1, pageSize = 99999) {
});
};
lbryProxy.collection_list({ page, page_size: pageSize, resolve_claims: 1 }).then(callback, failure);
lbryProxy.collection_list({ page, page_size: pageSize, resolve_claims: 1, resolve: true }).then(callback, failure);
};
}
@ -4354,7 +4361,8 @@ function doCollectionPublish(options, localId) {
function success(response) {
const collectionClaim = response.outputs[0];
dispatch(batchActions({
type: COLLECTION_PUBLISH_COMPLETED
type: COLLECTION_PUBLISH_COMPLETED,
data: { claimId: collectionClaim.claim_id }
},
// shift unpublished collection to pending collection with new publish id
// recent publish won't resolve this second. handle it in checkPending
@ -4401,13 +4409,11 @@ function doCollectionPublishUpdate(options) {
tags: [],
languages: options.languages || [],
locations: [],
blocking: true
blocking: true,
claim_id: options.claim_id,
clear_claims: true
};
if (options.claim_id) {
updateParams['claim_id'] = options.claim_id;
}
if (options.tags) {
updateParams['tags'] = options.tags.map(tag => tag.name);
}
@ -4429,6 +4435,10 @@ function doCollectionPublishUpdate(options) {
collectionClaim
}
});
dispatch({
type: COLLECTION_PENDING,
data: { claimId: collectionClaim.claim_id }
});
dispatch({
type: UPDATE_PENDING_CLAIMS,
data: {
@ -4532,6 +4542,7 @@ const doCheckPendingClaims = onConfirmed => (dispatch, getState) => {
pendingIdSet.delete(claimId);
if (Object.keys(pendingCollections).includes(claim.claim_id)) {
dispatch(doFetchItemsInCollection({ collectionId: claim.claim_id }));
dispatch(doCollectionDelete(claim.claim_id, 'pending'));
}
claimsToConfirm.push(claim);
if (onConfirmed) {
@ -4583,11 +4594,12 @@ const doLocalCollectionCreate = (name, collectionItems, type, sourceId) => dispa
});
};
const doLocalCollectionDelete = id => dispatch => {
const doCollectionDelete = (id, colKey = undefined, keepLocal) => dispatch => {
return dispatch({
type: COLLECTION_DELETE,
data: {
id: id
id: id,
collectionKey: colKey
}
});
};
@ -6411,8 +6423,17 @@ reducers[COLLECTION_PUBLISH_STARTED] = state => _extends$9({}, state, {
});
reducers[COLLECTION_PUBLISH_COMPLETED] = (state, action) => {
const myCollections = state.myCollectionClaims || [];
const myClaims = state.myClaims || [];
const { claimId } = action.data;
let myClaimIds = new Set(myClaims);
let myCollectionClaimsSet = new Set(myCollections);
myClaimIds.add(claimId);
myCollectionClaimsSet.add(claimId);
return Object.assign({}, state, {
creatingCollection: false
creatingCollection: false,
myClaims: Array.from(myClaimIds),
myCollectionClaims: Array.from(myCollectionClaimsSet)
});
};
@ -7766,6 +7787,7 @@ exports.doClearPublish = doClearPublish;
exports.doClearPurchasedUriSuccess = doClearPurchasedUriSuccess;
exports.doClearRepostError = doClearRepostError;
exports.doClearSupport = doClearSupport;
exports.doCollectionDelete = doCollectionDelete;
exports.doCollectionEdit = doCollectionEdit;
exports.doCollectionPublish = doCollectionPublish;
exports.doCollectionPublishUpdate = doCollectionPublishUpdate;
@ -7789,7 +7811,6 @@ exports.doFileList = doFileList;
exports.doGetNewAddress = doGetNewAddress;
exports.doImportChannel = doImportChannel;
exports.doLocalCollectionCreate = doLocalCollectionCreate;
exports.doLocalCollectionDelete = doLocalCollectionDelete;
exports.doPopulateSharedUserState = doPopulateSharedUserState;
exports.doPreferenceGet = doPreferenceGet;
exports.doPreferenceSet = doPreferenceSet;
@ -7851,6 +7872,7 @@ exports.makeSelectCollectionForIdHasClaimUrl = makeSelectCollectionForIdHasClaim
exports.makeSelectCollectionIsMine = makeSelectCollectionIsMine;
exports.makeSelectContentPositionForUri = makeSelectContentPositionForUri;
exports.makeSelectContentTypeForUri = makeSelectContentTypeForUri;
exports.makeSelectCountForCollectionId = makeSelectCountForCollectionId;
exports.makeSelectCoverForUri = makeSelectCoverForUri;
exports.makeSelectDateForUri = makeSelectDateForUri;
exports.makeSelectDownloadPathForUri = makeSelectDownloadPathForUri;

View file

@ -64,7 +64,7 @@ export {
doFetchItemsInCollection,
doFetchItemsInCollections,
doCollectionEdit,
doLocalCollectionDelete,
doCollectionDelete,
} from 'redux/actions/collections';
export {
@ -177,6 +177,7 @@ export {
makeSelectUrlsForCollectionId,
makeSelectClaimIdsForCollectionId,
makeSelectNameForCollectionId,
makeSelectCountForCollectionId,
makeSelectIsResolvingCollectionForId,
makeSelectNextUrlForCollection,
makeSelectCollectionForIdHasClaimUrl,

View file

@ -24,7 +24,11 @@ import {
makeSelectEditedCollectionForId,
selectPendingCollections,
} from 'redux/selectors/collections';
import { doFetchItemsInCollection, doFetchItemsInCollections } from 'redux/actions/collections';
import {
doFetchItemsInCollection,
doFetchItemsInCollections,
doCollectionDelete,
} from 'redux/actions/collections';
type ResolveEntries = Array<[string, GenericClaim]>;
@ -624,7 +628,10 @@ export function doFetchCollectionListMine(page: number = 1, pageSize: number = 9
});
};
Lbry.collection_list({ page, page_size: pageSize, resolve_claims: 1 }).then(callback, failure);
Lbry.collection_list({ page, page_size: pageSize, resolve_claims: 1, resolve: true }).then(
callback,
failure
);
};
}
@ -763,6 +770,7 @@ export function doCollectionPublish(
batchActions(
{
type: ACTIONS.COLLECTION_PUBLISH_COMPLETED,
data: { claimId: collectionClaim.claim_id },
},
// shift unpublished collection to pending collection with new publish id
// recent publish won't resolve this second. handle it in checkPending
@ -824,6 +832,7 @@ export function doCollectionPublishUpdate(options: {
tags?: Array<string>,
languages?: Array<string>,
claims?: Array<string>,
clear_claims: boolean,
} = {
bid: creditsToString(options.bid),
title: options.title,
@ -834,6 +843,7 @@ export function doCollectionPublishUpdate(options: {
locations: [],
blocking: true,
claim_id: options.claim_id,
clear_claims: true,
};
if (options.tags) {
@ -857,6 +867,10 @@ export function doCollectionPublishUpdate(options: {
collectionClaim,
},
});
dispatch({
type: ACTIONS.COLLECTION_PENDING,
data: { claimId: collectionClaim.claim_id },
});
dispatch({
type: ACTIONS.UPDATE_PENDING_CLAIMS,
data: {
@ -964,6 +978,7 @@ export const doCheckPendingClaims = (onConfirmed: Function) => (
pendingIdSet.delete(claimId);
if (Object.keys(pendingCollections).includes(claim.claim_id)) {
dispatch(doFetchItemsInCollection({ collectionId: claim.claim_id }));
dispatch(doCollectionDelete(claim.claim_id, 'pending'));
}
claimsToConfirm.push(claim);
if (onConfirmed) {

View file

@ -40,11 +40,16 @@ export const doLocalCollectionCreate = (
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
});
};
export const doLocalCollectionDelete = (id: string) => (dispatch: Dispatch) => {
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
export const doCollectionDelete = (
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
id: string,
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
colKey: ?string = undefined,
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
keepLocal?: boolean
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
) => (dispatch: Dispatch) => {
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
return dispatch({
type: ACTIONS.COLLECTION_DELETE,
data: {
id: id,
collectionKey: colKey,
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
},
});
};

jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >
jessopb commented 2021-02-17 17:16:08 +01:00 (Migrated from github.com)
Review

Array/< { claimId: string, items: ?Array } >

Array/< { claimId: string, items: ?Array<GenericClaim> } >

View file

@ -606,8 +606,17 @@ reducers[ACTIONS.COLLECTION_PUBLISH_STARTED] = (state: State): State => ({
});
reducers[ACTIONS.COLLECTION_PUBLISH_COMPLETED] = (state: State, action: any): State => {
const myCollections = state.myCollectionClaims || [];
const myClaims = state.myClaims || [];
const { claimId } = action.data;
let myClaimIds = new Set(myClaims);
let myCollectionClaimsSet = new Set(myCollections);
myClaimIds.add(claimId);
myCollectionClaimsSet.add(claimId);
return Object.assign({}, state, {
creatingCollection: false,
myClaims: Array.from(myClaimIds),
myCollectionClaims: Array.from(myCollectionClaimsSet),
});
};

View file

@ -203,3 +203,14 @@ export const makeSelectNameForCollectionId = (id: string) =>
return (collection && collection.name) || '';
}
);
export const makeSelectCountForCollectionId = (id: string) =>
createSelector(
makeSelectCollectionForId(id),
collection => {
if (collection.itemCount !== undefined) {
return collection.itemCount;
}
return collection.items.length;
}
);