handle collection claim delete

This commit is contained in:
zeppi 2021-05-26 11:36:17 -04:00 committed by jessopb
parent 06ce8c623c
commit bfb50ebeb5
4 changed files with 54 additions and 52 deletions

44
dist/bundle.es.js vendored
View file

@ -4598,14 +4598,21 @@ const doLocalCollectionCreate = (name, collectionItems, type, sourceId) => dispa
}); });
}; };
const doCollectionDelete = (id, colKey = undefined) => dispatch => { const doCollectionDelete = (id, colKey = undefined) => (dispatch, getState) => {
return dispatch({ const state = getState();
const claim = makeSelectClaimForClaimId(id)(state);
const collectionDelete = () => dispatch({
type: COLLECTION_DELETE, type: COLLECTION_DELETE,
data: { data: {
id: id, id: id,
collectionKey: colKey collectionKey: colKey
} }
}); });
if (claim) {
const { txid, nout } = claim;
return dispatch(doAbandonClaim(txid, nout, collectionDelete));
}
return collectionDelete();
}; };
// Given a collection, save its collectionId to be resolved and displayed in Library // Given a collection, save its collectionId to be resolved and displayed in Library
@ -4645,10 +4652,11 @@ const doFetchItemsInCollections = (resolveItemsOptions, resolveStartedCallback)
const sortResults = function (results, claimList) { const sortResults = function (results, claimList) {
const newResults = []; const newResults = [];
claimList.forEach(function (id) { claimList.forEach(function (id) {
const item = results.pop(function (i) { const index = results.findIndex(function (i) {
return i.claim_id === id; return i.claim_id === id;
}); });
if (item) newResults.push(item); const item = results.splice(index, 1);
if (item) newResults.push(item[0]);
}); });
return newResults; return newResults;
}; };
@ -6391,6 +6399,7 @@ reducers[ABANDON_CLAIM_SUCCEEDED] = (state, action) => {
const newMyClaims = state.myClaims ? state.myClaims.slice() : []; const newMyClaims = state.myClaims ? state.myClaims.slice() : [];
const newMyChannelClaims = state.myChannelClaims ? state.myChannelClaims.slice() : []; const newMyChannelClaims = state.myChannelClaims ? state.myChannelClaims.slice() : [];
const claimsByUri = Object.assign({}, state.claimsByUri); const claimsByUri = Object.assign({}, state.claimsByUri);
const newMyCollectionClaims = state.myCollectionClaims ? state.myCollectionClaims.slice() : [];
Object.keys(claimsByUri).forEach(uri => { Object.keys(claimsByUri).forEach(uri => {
if (claimsByUri[uri] === claimId) { if (claimsByUri[uri] === claimId) {
@ -6399,12 +6408,14 @@ reducers[ABANDON_CLAIM_SUCCEEDED] = (state, action) => {
}); });
const myClaims = newMyClaims.filter(i => i !== claimId); const myClaims = newMyClaims.filter(i => i !== claimId);
const myChannelClaims = newMyChannelClaims.filter(i => i !== claimId); const myChannelClaims = newMyChannelClaims.filter(i => i !== claimId);
const myCollectionClaims = newMyCollectionClaims.filter(i => i !== claimId);
delete byId[claimId]; delete byId[claimId];
return Object.assign({}, state, { return Object.assign({}, state, {
myClaims, myClaims,
myChannelClaims, myChannelClaims,
myCollectionClaims,
byId, byId,
claimsByUri claimsByUri
}); });
@ -7545,14 +7556,14 @@ const getTimestamp$1 = () => {
const defaultState$6 = { const defaultState$6 = {
builtin: { builtin: {
watchlater: { watchlater: {
items: ['lbry://why-wolves-determine-the-shape-of-rivers#d8a60a057ac9adb6b618be6985ca8361c730c02e'], items: [],
id: WATCH_LATER_ID, id: WATCH_LATER_ID,
name: 'Watch Later', name: 'Watch Later',
updatedAt: getTimestamp$1(), updatedAt: getTimestamp$1(),
type: COL_TYPE_PLAYLIST type: COL_TYPE_PLAYLIST
}, },
favorites: { favorites: {
items: ['lbry://why-wolves-determine-the-shape-of-rivers#d8a60a057ac9adb6b618be6985ca8361c730c02e'], items: [],
id: FAVORITES_ID, id: FAVORITES_ID,
name: 'Favorites', name: 'Favorites',
type: COL_TYPE_PLAYLIST, type: COL_TYPE_PLAYLIST,
@ -7626,22 +7637,15 @@ const collectionsReducer = handleActions({
const newUnpublishedList = Object.assign({}, unpublishedList); const newUnpublishedList = Object.assign({}, unpublishedList);
const newPendingList = Object.assign({}, pendingList); const newPendingList = Object.assign({}, pendingList);
const isEdit = editList[localId || claimId]; const isEdit = editList[claimId];
if (localId) { if (localId) {
// pending from unpublished -> published // new publish
// delete from local newPendingList[claimId] = Object.assign({}, newUnpublishedList[localId] || {});
newPendingList[claimId] = Object.assign({}, newEditList[localId] || newUnpublishedList[localId] || {}); delete newUnpublishedList[localId];
if (isEdit) {
delete newEditList[localId];
} else {
delete newUnpublishedList[localId];
}
} else { } else {
// pending from edited published -> published // edit update
if (isEdit) { newPendingList[claimId] = Object.assign({}, newEditList[claimId]);
newPendingList[claimId] = Object.assign({}, newEditList[claimId]); delete newEditList[claimId];
delete newEditList[claimId];
}
} }
return _extends$e({}, state, { return _extends$e({}, state, {

View file

@ -2,7 +2,7 @@
import * as ACTIONS from 'constants/action_types'; import * as ACTIONS from 'constants/action_types';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
import Lbry from 'lbry'; import Lbry from 'lbry';
import { doClaimSearch } from 'redux/actions/claims'; import { doClaimSearch, doAbandonClaim } from 'redux/actions/claims';
import { makeSelectClaimForClaimId } from 'redux/selectors/claims'; import { makeSelectClaimForClaimId } from 'redux/selectors/claims';
import { import {
makeSelectCollectionForId, makeSelectCollectionForId,
@ -42,15 +42,24 @@ export const doLocalCollectionCreate = (
}; };
export const doCollectionDelete = (id: string, colKey: ?string = undefined) => ( export const doCollectionDelete = (id: string, colKey: ?string = undefined) => (
dispatch: Dispatch dispatch: Dispatch,
getState: GetState
) => { ) => {
return dispatch({ const state = getState();
type: ACTIONS.COLLECTION_DELETE, const claim = makeSelectClaimForClaimId(id)(state);
data: { const collectionDelete = () =>
id: id, dispatch({
collectionKey: colKey, type: ACTIONS.COLLECTION_DELETE,
}, data: {
}); id: id,
collectionKey: colKey,
},
});
if (claim) {
const { txid, nout } = claim;
return dispatch(doAbandonClaim(txid, nout, collectionDelete));
}
return collectionDelete();
}; };
// Given a collection, save its collectionId to be resolved and displayed in Library // Given a collection, save its collectionId to be resolved and displayed in Library

View file

@ -528,6 +528,7 @@ reducers[ACTIONS.ABANDON_CLAIM_SUCCEEDED] = (state: State, action: any): State =
const newMyClaims = state.myClaims ? state.myClaims.slice() : []; const newMyClaims = state.myClaims ? state.myClaims.slice() : [];
const newMyChannelClaims = state.myChannelClaims ? state.myChannelClaims.slice() : []; const newMyChannelClaims = state.myChannelClaims ? state.myChannelClaims.slice() : [];
const claimsByUri = Object.assign({}, state.claimsByUri); const claimsByUri = Object.assign({}, state.claimsByUri);
const newMyCollectionClaims = state.myCollectionClaims ? state.myCollectionClaims.slice() : [];
Object.keys(claimsByUri).forEach(uri => { Object.keys(claimsByUri).forEach(uri => {
if (claimsByUri[uri] === claimId) { if (claimsByUri[uri] === claimId) {
@ -536,12 +537,14 @@ reducers[ACTIONS.ABANDON_CLAIM_SUCCEEDED] = (state: State, action: any): State =
}); });
const myClaims = newMyClaims.filter(i => i !== claimId); const myClaims = newMyClaims.filter(i => i !== claimId);
const myChannelClaims = newMyChannelClaims.filter(i => i !== claimId); const myChannelClaims = newMyChannelClaims.filter(i => i !== claimId);
const myCollectionClaims = newMyCollectionClaims.filter(i => i !== claimId);
delete byId[claimId]; delete byId[claimId];
return Object.assign({}, state, { return Object.assign({}, state, {
myClaims, myClaims,
myChannelClaims, myChannelClaims,
myCollectionClaims,
byId, byId,
claimsByUri, claimsByUri,
}); });

View file

@ -10,18 +10,14 @@ const getTimestamp = () => {
const defaultState: CollectionState = { const defaultState: CollectionState = {
builtin: { builtin: {
watchlater: { watchlater: {
items: [ items: [],
'lbry://why-wolves-determine-the-shape-of-rivers#d8a60a057ac9adb6b618be6985ca8361c730c02e',
],
id: COLS.WATCH_LATER_ID, id: COLS.WATCH_LATER_ID,
name: 'Watch Later', name: 'Watch Later',
updatedAt: getTimestamp(), updatedAt: getTimestamp(),
type: COLS.COL_TYPE_PLAYLIST, type: COLS.COL_TYPE_PLAYLIST,
}, },
favorites: { favorites: {
items: [ items: [],
'lbry://why-wolves-determine-the-shape-of-rivers#d8a60a057ac9adb6b618be6985ca8361c730c02e',
],
id: COLS.FAVORITES_ID, id: COLS.FAVORITES_ID,
name: 'Favorites', name: 'Favorites',
type: COLS.COL_TYPE_PLAYLIST, type: COLS.COL_TYPE_PLAYLIST,
@ -99,25 +95,15 @@ const collectionsReducer = handleActions(
const newUnpublishedList = Object.assign({}, unpublishedList); const newUnpublishedList = Object.assign({}, unpublishedList);
const newPendingList = Object.assign({}, pendingList); const newPendingList = Object.assign({}, pendingList);
const isEdit = editList[localId || claimId]; const isEdit = editList[claimId];
if (localId) { if (localId) {
// pending from unpublished -> published // new publish
// delete from local newPendingList[claimId] = Object.assign({}, newUnpublishedList[localId] || {});
newPendingList[claimId] = Object.assign( delete newUnpublishedList[localId];
{},
newEditList[localId] || newUnpublishedList[localId] || {}
);
if (isEdit) {
delete newEditList[localId];
} else {
delete newUnpublishedList[localId];
}
} else { } else {
// pending from edited published -> published // edit update
if (isEdit) { newPendingList[claimId] = Object.assign({}, newEditList[claimId]);
newPendingList[claimId] = Object.assign({}, newEditList[claimId]); delete newEditList[claimId];
delete newEditList[claimId];
}
} }
return { return {