Collections #383
1227
dist/bundle.es.js
vendored
|
@ -1,5 +1,10 @@
|
||||||
export const COLLECTION_ID = 'colid';
|
export const COLLECTION_ID = 'colid';
|
||||||
export const COLLECTION_INDEX = 'colindex';
|
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 WATCH_LATER_ID = 'watchlater';
|
||||||
export const FAVORITES_ID = 'favorites';
|
export const FAVORITES_ID = 'favorites';
|
||||||
|
export const FAVORITE_CHANNELS_ID = 'favoriteChannels';
|
||||||
|
export const BUILTIN_LISTS = [WATCH_LATER_ID, FAVORITES_ID, FAVORITE_CHANNELS_ID];
|
||||||
|
|
|
@ -422,7 +422,7 @@ export function doCreateChannel(name: string, amount: number, optionalParams: an
|
||||||
description?: string,
|
description?: string,
|
||||||
website_url?: string,
|
website_url?: string,
|
||||||
email?: string,
|
email?: string,
|
||||||
tags?: Array<string>,
|
tags?: Array<Tag>,
|
||||||
languages?: Array<string>,
|
languages?: Array<string>,
|
||||||
} = {
|
} = {
|
||||||
name,
|
name,
|
||||||
|
@ -801,11 +801,12 @@ export function doCollectionPublishUpdate(options: {
|
||||||
bid?: string,
|
bid?: string,
|
||||||
blocking?: true,
|
blocking?: true,
|
||||||
title?: string,
|
title?: string,
|
||||||
thumbnail_url?: string,
|
thumbnailUrl?: string,
|
||||||
description?: string,
|
description?: string,
|
||||||
claim_id: string,
|
claim_id: string,
|
||||||
tags?: Array<string>,
|
tags?: Array<Tag>,
|
||||||
languages?: Array<string>,
|
languages?: Array<string>,
|
||||||
|
claims?: Array<string>,
|
||||||
}) {
|
}) {
|
||||||
return (dispatch: Dispatch, getState: GetState) => {
|
return (dispatch: Dispatch, getState: GetState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
@ -813,12 +814,35 @@ export function doCollectionPublishUpdate(options: {
|
||||||
// get publish params from claim
|
// get publish params from claim
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
|
|
||||||
const collectionClaim = makeSelectClaimForClaimId(options.claim_id)(state);
|
const updateParams: {
|
||||||
// TODO: add old claim entries to params
|
bid?: string,
|
||||||
const editItems = makeSelectEditedCollectionForId(options.claim_id)(state);
|
blocking?: true,
|
||||||
const oldParams: CollectionUpdateParams = {
|
title?: string,
|
||||||
bid: collectionClaim.amount,
|
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
|
// $FlowFixMe
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -839,6 +863,7 @@ export function doCollectionPublishUpdate(options: {
|
||||||
claims: [collectionClaim],
|
claims: [collectionClaim],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
dispatch(doCheckPendingClaims());
|
||||||
dispatch(doFetchCollectionListMine(1, 10));
|
dispatch(doFetchCollectionListMine(1, 10));
|
||||||
resolve(collectionClaim);
|
resolve(collectionClaim);
|
||||||
}
|
}
|
||||||
|
@ -852,7 +877,7 @@ export function doCollectionPublishUpdate(options: {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Lbry.collection_update(options).then(success, failure);
|
Lbry.collection_update(updateParams).then(success, failure);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,7 @@ import {
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
makeSelectUnpublishedCollectionForId,
|
makeSelectUnpublishedCollectionForId,
|
||||||
makeSelectEditedCollectionForId,
|
makeSelectEditedCollectionForId,
|
||||||
} from 'redux/selectors/collections';
|
} from 'redux/selectors/collections';
|
||||||
const WATCH_LATER_ID = 'watchlater';
|
import * as COLS from 'constants/collections';
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
const FAVORITES_ID = 'favorites';
|
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
|
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
const BUILTIN_LISTS = [WATCH_LATER_ID, FAVORITES_ID];
|
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
|
|
||||||
const getTimestamp = () => {
|
const getTimestamp = () => {
|
||||||
return Math.floor(Date.now() / 1000);
|
return Math.floor(Date.now() / 1000);
|
||||||
|
@ -37,7 +34,7 @@ export const doLocalCollectionCreate = (
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
updatedAt: getTimestamp(),
|
updatedAt: getTimestamp(),
|
||||||
items: collectionItems || [],
|
items: collectionItems || [],
|
||||||
sourceId: sourceId,
|
sourceId: sourceId,
|
||||||
type: type || 'collection',
|
type: type,
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -343,7 +340,7 @@ export const doCollectionEdit = (collectionId: string, params: CollectionEditPar
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
let currentItems = collection.items ? collection.items.concat() : [];
|
let currentItems = collection.items ? collection.items.concat() : [];
|
||||||
const { claims: passedClaims, order, claimIds, replace, remove, type } = params;
|
const { claims: passedClaims, order, claimIds, replace, remove, type } = params;
|
||||||
|
|
||||||
const collectionType = type || 'collection';
|
const collectionType = type || collection.type;
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
let newItems: Array<?string> = currentItems;
|
let newItems: Array<?string> = currentItems;
|
||||||
|
|
||||||
if (passedClaims) {
|
if (passedClaims) {
|
||||||
|
@ -430,7 +427,7 @@ export const doCollectionEdit = (collectionId: string, params: CollectionEditPar
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (BUILTIN_LISTS.includes(collectionId)) {
|
} else if (COLS.BUILTIN_LISTS.includes(collectionId)) {
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.COLLECTION_EDIT,
|
type: ACTIONS.COLLECTION_EDIT,
|
||||||
data: {
|
data: {
|
||||||
|
|
||||||
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
Array/< { claimId: string, items: ?Array } > Array/< { claimId: string, items: ?Array<GenericClaim> } >
|
|
@ -341,15 +341,12 @@ reducers[ACTIONS.FETCH_COLLECTION_LIST_COMPLETED] = (state: State, action: any):
|
||||||
const myClaims = state.myClaims || [];
|
const myClaims = state.myClaims || [];
|
||||||
let myClaimIds = new Set(myClaims);
|
let myClaimIds = new Set(myClaims);
|
||||||
const pendingIds = state.pendingIds || [];
|
const pendingIds = state.pendingIds || [];
|
||||||
let myCollectionClaims;
|
let myCollectionClaimsSet = new Set([]);
|
||||||
const byId = Object.assign({}, state.byId);
|
const byId = Object.assign({}, state.byId);
|
||||||
const byUri = Object.assign({}, state.claimsByUri);
|
const byUri = Object.assign({}, state.claimsByUri);
|
||||||
|
|
||||||
if (!claims.length) {
|
if (claims.length) {
|
||||||
// $FlowFixMe
|
myCollectionClaimsSet = new Set(state.myCollectionClaims);
|
||||||
myCollectionClaims = null;
|
|
||||||
} else {
|
|
||||||
myCollectionClaims = new Set(state.myCollectionClaims);
|
|
||||||
claims.forEach(claim => {
|
claims.forEach(claim => {
|
||||||
const { meta } = claim;
|
const { meta } = claim;
|
||||||
const { canonical_url: canonicalUrl, permanent_url: permanentUrl, claim_id: claimId } = 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;
|
byUri[permanentUrl] = claimId;
|
||||||
|
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
myCollectionClaims.add(claimId);
|
myCollectionClaimsSet.add(claimId);
|
||||||
// we don't want to overwrite a pending result with a resolve
|
// we don't want to overwrite a pending result with a resolve
|
||||||
if (!pendingIds.some(c => c === claimId)) {
|
if (!pendingIds.some(c => c === claimId)) {
|
||||||
byId[claimId] = claim;
|
byId[claimId] = claim;
|
||||||
|
@ -373,7 +370,7 @@ reducers[ACTIONS.FETCH_COLLECTION_LIST_COMPLETED] = (state: State, action: any):
|
||||||
byId,
|
byId,
|
||||||
claimsByUri: byUri,
|
claimsByUri: byUri,
|
||||||
fetchingMyCollections: false,
|
fetchingMyCollections: false,
|
||||||
myCollectionClaims: myCollectionClaims ? Array.from(myCollectionClaims) : null,
|
myCollectionClaims: Array.from(myCollectionClaimsSet),
|
||||||
myClaims: myClaimIds ? Array.from(myClaimIds) : null,
|
myClaims: myClaimIds ? Array.from(myClaimIds) : null,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { handleActions } from 'util/redux-utils';
|
import { handleActions } from 'util/redux-utils';
|
||||||
import * as ACTIONS from 'constants/action_types';
|
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 = () => {
|
const getTimestamp = () => {
|
||||||
return Math.floor(Date.now() / 1000);
|
return Math.floor(Date.now() / 1000);
|
||||||
};
|
};
|
||||||
|
@ -14,17 +10,21 @@ const getTimestamp = () => {
|
||||||
const defaultState: CollectionState = {
|
const defaultState: CollectionState = {
|
||||||
builtin: {
|
builtin: {
|
||||||
watchlater: {
|
watchlater: {
|
||||||
items: ['lbry://seriouspublish#c1b740eb88f96b465f65e5f1542564539df1c62e'],
|
items: [
|
||||||
id: WATCH_LATER_ID,
|
'lbry://why-wolves-determine-the-shape-of-rivers#d8a60a057ac9adb6b618be6985ca8361c730c02e',
|
||||||
|
],
|
||||||
|
id: COLS.WATCH_LATER_ID,
|
||||||
name: 'Watch Later',
|
name: 'Watch Later',
|
||||||
updatedAt: getTimestamp(),
|
updatedAt: getTimestamp(),
|
||||||
type: 'playlist',
|
type: COLS.COL_TYPE_PLAYLIST,
|
||||||
},
|
},
|
||||||
favorites: {
|
favorites: {
|
||||||
items: ['lbry://seriouspublish#c1b740eb88f96b465f65e5f1542564539df1c62e'],
|
items: [
|
||||||
id: FAVORITES_ID,
|
'lbry://why-wolves-determine-the-shape-of-rivers#d8a60a057ac9adb6b618be6985ca8361c730c02e',
|
||||||
|
],
|
||||||
|
id: COLS.FAVORITES_ID,
|
||||||
name: 'Favorites',
|
name: 'Favorites',
|
||||||
type: 'collection',
|
type: COLS.COL_TYPE_PLAYLIST,
|
||||||
updatedAt: getTimestamp(),
|
updatedAt: getTimestamp(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -47,7 +47,7 @@ const collectionsReducer = handleActions(
|
||||||
name: params.name,
|
name: params.name,
|
||||||
items: [],
|
items: [],
|
||||||
updatedAt: getTimestamp(),
|
updatedAt: getTimestamp(),
|
||||||
type: params.type || 'mixed',
|
type: params.type,
|
||||||
};
|
};
|
||||||
|
|
||||||
const newList = Object.assign({}, newListTemplate, { ...params });
|
const newList = Object.assign({}, newListTemplate, { ...params });
|
||||||
|
@ -131,7 +131,7 @@ const collectionsReducer = handleActions(
|
||||||
[ACTIONS.COLLECTION_EDIT]: (state, action) => {
|
[ACTIONS.COLLECTION_EDIT]: (state, action) => {
|
||||||
const { id, collectionKey, collection } = action.data;
|
const { id, collectionKey, collection } = action.data;
|
||||||
|
|
||||||
if (BUILTIN_LISTS.includes(id)) {
|
if (COLS.BUILTIN_LISTS.includes(id)) {
|
||||||
const { builtin: lists } = state;
|
const { builtin: lists } = state;
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|
|
@ -162,7 +162,7 @@ export const makeSelectCollectionForId = (id: string) =>
|
||||||
export const makeSelectCollectionForIdHasClaimUrl = (id: string, url: string) =>
|
export const makeSelectCollectionForIdHasClaimUrl = (id: string, url: string) =>
|
||||||
createSelector(
|
createSelector(
|
||||||
makeSelectCollectionForId(id),
|
makeSelectCollectionForId(id),
|
||||||
collection => collection.items.includes(url)
|
collection => collection && collection.items.includes(url)
|
||||||
);
|
);
|
||||||
|
|
||||||
export const makeSelectUrlsForCollectionId = (id: string) =>
|
export const makeSelectUrlsForCollectionId = (id: string) =>
|
||||||
|
|
Array/< { claimId: string, items: ?Array } >