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

38
dist/bundle.es.js vendored
View file

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

View file

@ -2,7 +2,7 @@
import * as ACTIONS from 'constants/action_types';
import { v4 as uuid } from 'uuid';
import Lbry from 'lbry';
import { doClaimSearch } from 'redux/actions/claims';
import { doClaimSearch, doAbandonClaim } from 'redux/actions/claims';
import { makeSelectClaimForClaimId } from 'redux/selectors/claims';
import {
makeSelectCollectionForId,
@ -42,15 +42,24 @@ export const doLocalCollectionCreate = (
};
export const doCollectionDelete = (id: string, colKey: ?string = undefined) => (
dispatch: Dispatch
dispatch: Dispatch,
getState: GetState
) => {
return dispatch({
const state = getState();
const claim = makeSelectClaimForClaimId(id)(state);
const collectionDelete = () =>
dispatch({
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

View file

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

View file

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