Collections #383

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

1227
dist/bundle.es.js vendored

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,10 @@
export const COLLECTION_ID = 'colid';
export const COLLECTION_INDEX = 'colindex';
export const COL_TYPE_PLAYLIST = 'playlist';
export const COL_TYPE_CHANNELS = 'channelCollection';
export const WATCH_LATER_ID = 'watchlater';
export const FAVORITES_ID = 'favorites';
export const FAVORITE_CHANNELS_ID = 'favoriteChannels';
export const BUILTIN_LISTS = [WATCH_LATER_ID, FAVORITES_ID, FAVORITE_CHANNELS_ID];

View file

@ -422,7 +422,7 @@ export function doCreateChannel(name: string, amount: number, optionalParams: an
description?: string,
website_url?: string,
email?: string,
tags?: Array<string>,
tags?: Array<Tag>,
languages?: Array<string>,
} = {
name,
@ -801,11 +801,12 @@ export function doCollectionPublishUpdate(options: {
bid?: string,
blocking?: true,
title?: string,
thumbnail_url?: string,
thumbnailUrl?: string,
description?: string,
claim_id: string,
tags?: Array<string>,
tags?: Array<Tag>,
languages?: Array<string>,
claims?: Array<string>,
}) {
return (dispatch: Dispatch, getState: GetState) => {
const state = getState();
@ -813,12 +814,35 @@ export function doCollectionPublishUpdate(options: {
// get publish params from claim
// $FlowFixMe
const collectionClaim = makeSelectClaimForClaimId(options.claim_id)(state);
// TODO: add old claim entries to params
const editItems = makeSelectEditedCollectionForId(options.claim_id)(state);
const oldParams: CollectionUpdateParams = {
bid: collectionClaim.amount,
const updateParams: {
bid?: string,
blocking?: true,
title?: string,
thumbnail_url?: string,
description?: string,
claim_id: string,
tags?: Array<string>,
languages?: Array<string>,
claims?: Array<string>,
} = {
bid: creditsToString(options.bid),
title: options.title,
thumbnail_url: options.thumbnailUrl,
description: options.description,
tags: [],
languages: options.languages || [],
locations: [],
blocking: true,
claim_id: options.claim_id,
};
if (options.tags) {
updateParams['tags'] = options.tags.map(tag => tag.name);
}
if (options.claims) {
updateParams['claims'] = options.claims;
}
// $FlowFixMe
return new Promise(resolve => {
dispatch({
@ -839,6 +863,7 @@ export function doCollectionPublishUpdate(options: {
claims: [collectionClaim],
},
});
dispatch(doCheckPendingClaims());
dispatch(doFetchCollectionListMine(1, 10));
resolve(collectionClaim);
}
@ -852,7 +877,7 @@ export function doCollectionPublishUpdate(options: {
});
}
Lbry.collection_update(options).then(success, failure);
Lbry.collection_update(updateParams).then(success, failure);
});
};
}

View file

@ -12,10 +12,7 @@ import {
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> } >
makeSelectUnpublishedCollectionForId,
makeSelectEditedCollectionForId,
} from 'redux/selectors/collections';
const WATCH_LATER_ID = 'watchlater';
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> } >
const FAVORITES_ID = 'favorites';
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> } >
const BUILTIN_LISTS = [WATCH_LATER_ID, FAVORITES_ID];
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> } >
import * as COLS from 'constants/collections';
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> } >
const getTimestamp = () => {
return Math.floor(Date.now() / 1000);
@ -37,7 +34,7 @@ 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> } >
updatedAt: getTimestamp(),
items: collectionItems || [],
sourceId: sourceId,
type: type || 'collection',
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> } >
type: type,
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> } >
},
},
});
@ -343,7 +340,7 @@ export const doCollectionEdit = (collectionId: string, params: CollectionEditPar
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> } >
let currentItems = collection.items ? collection.items.concat() : [];
const { claims: passedClaims, order, claimIds, replace, remove, type } = params;
const collectionType = type || 'collection';
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> } >
const collectionType = type || collection.type;
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> } >
let newItems: Array<?string> = currentItems;
if (passedClaims) {
@ -430,7 +427,7 @@ export const doCollectionEdit = (collectionId: string, params: CollectionEditPar
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> } >
},
},
});
} else if (BUILTIN_LISTS.includes(collectionId)) {
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> } >
} else if (COLS.BUILTIN_LISTS.includes(collectionId)) {
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({
type: ACTIONS.COLLECTION_EDIT,
data: {

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

@ -341,15 +341,12 @@ reducers[ACTIONS.FETCH_COLLECTION_LIST_COMPLETED] = (state: State, action: any):
const myClaims = state.myClaims || [];
let myClaimIds = new Set(myClaims);
const pendingIds = state.pendingIds || [];
let myCollectionClaims;
let myCollectionClaimsSet = new Set([]);
const byId = Object.assign({}, state.byId);
const byUri = Object.assign({}, state.claimsByUri);
if (!claims.length) {
// $FlowFixMe
myCollectionClaims = null;
} else {
myCollectionClaims = new Set(state.myCollectionClaims);
if (claims.length) {
myCollectionClaimsSet = new Set(state.myCollectionClaims);
claims.forEach(claim => {
const { meta } = claim;
const { canonical_url: canonicalUrl, permanent_url: permanentUrl, claim_id: claimId } = claim;
@ -359,7 +356,7 @@ reducers[ACTIONS.FETCH_COLLECTION_LIST_COMPLETED] = (state: State, action: any):
byUri[permanentUrl] = claimId;
// $FlowFixMe
myCollectionClaims.add(claimId);
myCollectionClaimsSet.add(claimId);
// we don't want to overwrite a pending result with a resolve
if (!pendingIds.some(c => c === claimId)) {
byId[claimId] = claim;
@ -373,7 +370,7 @@ reducers[ACTIONS.FETCH_COLLECTION_LIST_COMPLETED] = (state: State, action: any):
byId,
claimsByUri: byUri,
fetchingMyCollections: false,
myCollectionClaims: myCollectionClaims ? Array.from(myCollectionClaims) : null,
myCollectionClaims: Array.from(myCollectionClaimsSet),
myClaims: myClaimIds ? Array.from(myClaimIds) : null,
};
};

View file

@ -1,12 +1,8 @@
// @flow
import { handleActions } from 'util/redux-utils';
import * as ACTIONS from 'constants/action_types';
import * as COLLECTION_CONSTS from 'constants/collections';
import * as COLS from 'constants/collections';
const WATCH_LATER_ID = 'watchlater';
const FAVORITES_ID = 'favorites';
const BUILTIN_LISTS = [WATCH_LATER_ID, FAVORITES_ID];
const getTimestamp = () => {
return Math.floor(Date.now() / 1000);
};
@ -14,17 +10,21 @@ const getTimestamp = () => {
const defaultState: CollectionState = {
builtin: {
watchlater: {
items: ['lbry://seriouspublish#c1b740eb88f96b465f65e5f1542564539df1c62e'],
id: WATCH_LATER_ID,
items: [
'lbry://why-wolves-determine-the-shape-of-rivers#d8a60a057ac9adb6b618be6985ca8361c730c02e',
],
id: COLS.WATCH_LATER_ID,
name: 'Watch Later',
updatedAt: getTimestamp(),
type: 'playlist',
type: COLS.COL_TYPE_PLAYLIST,
},
favorites: {
items: ['lbry://seriouspublish#c1b740eb88f96b465f65e5f1542564539df1c62e'],
id: FAVORITES_ID,
items: [
'lbry://why-wolves-determine-the-shape-of-rivers#d8a60a057ac9adb6b618be6985ca8361c730c02e',
],
id: COLS.FAVORITES_ID,
name: 'Favorites',
type: 'collection',
type: COLS.COL_TYPE_PLAYLIST,
updatedAt: getTimestamp(),
},
},
@ -47,7 +47,7 @@ const collectionsReducer = handleActions(
name: params.name,
items: [],
updatedAt: getTimestamp(),
type: params.type || 'mixed',
type: params.type,
};
const newList = Object.assign({}, newListTemplate, { ...params });
@ -131,7 +131,7 @@ const collectionsReducer = handleActions(
[ACTIONS.COLLECTION_EDIT]: (state, action) => {
const { id, collectionKey, collection } = action.data;
if (BUILTIN_LISTS.includes(id)) {
if (COLS.BUILTIN_LISTS.includes(id)) {
const { builtin: lists } = state;
return {
...state,

View file

@ -162,7 +162,7 @@ export const makeSelectCollectionForId = (id: string) =>
export const makeSelectCollectionForIdHasClaimUrl = (id: string, url: string) =>
createSelector(
makeSelectCollectionForId(id),
collection => collection.items.includes(url)
collection => collection && collection.items.includes(url)
);
export const makeSelectUrlsForCollectionId = (id: string) =>