Corrects abandon return type & fixes issue where redux wasn't being changed

This commit is contained in:
Oleg Silkin 2020-01-21 00:46:14 -05:00
parent 1e1fcb8b18
commit bc2436dce2
5 changed files with 61 additions and 45 deletions

62
dist/bundle.es.js vendored
View file

@ -4067,7 +4067,7 @@ const doUpdateSearchOptions = newOptions => (dispatch, getState) => {
} }
}; };
// //
function savePosition(claimId, outpoint, position) { function savePosition(claimId, outpoint, position) {
return dispatch => { return dispatch => {
@ -4204,13 +4204,20 @@ function doCommentAbandon(comment_id) {
return lbryProxy.comment_abandon({ return lbryProxy.comment_abandon({
comment_id: comment_id comment_id: comment_id
}).then(result => { }).then(result => {
dispatch({ // Comment may not be deleted if the signing channel can't be signed.
type: COMMENT_ABANDON_COMPLETED, // This will happen if the channel was recently created or abandoned.
data: { if (result.abandoned) {
comment_id: comment_id, dispatch({
abandoned: result type: COMMENT_ABANDON_COMPLETED,
} data: {
}); comment_id: comment_id
}
});
} else {
dispatch({
type: COMMENT_ABANDON_FAILED
});
}
}).catch(error => { }).catch(error => {
dispatch({ dispatch({
type: COMMENT_ABANDON_FAILED, type: COMMENT_ABANDON_FAILED,
@ -4740,35 +4747,36 @@ const commentReducer = handleActions({
[COMMENT_LIST_FAILED]: (state, action) => _extends$8({}, state, { [COMMENT_LIST_FAILED]: (state, action) => _extends$8({}, state, {
isLoading: false isLoading: false
}), }),
[COMMENT_ABANDON_STARTED]: (state, action) => _extends$7({}, state, { [COMMENT_ABANDON_STARTED]: (state, action) => _extends$8({}, state, {
isLoading: true isLoading: true
}), }),
// remove the existing comment from the id -> comment list and claim -> commentIds
[COMMENT_ABANDON_COMPLETED]: (state, action) => { [COMMENT_ABANDON_COMPLETED]: (state, action) => {
const { comment_id, abandoned } = action.data; const { comment_id } = action.data;
const commentById = Object.assign({}, state.commentById); const commentById = Object.assign({}, state.commentById);
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
if (abandoned && comment_id in abandoned) { // to remove the comment and its references
// messy but necessary for the time being const claimId = commentById[comment_id].claim_id;
const comment = commentById[comment_id]; for (let i = 0; i < byId[claimId].length; i++) {
const commentIds = byId[comment.claim_id]; if (byId[claimId][i] === comment_id) {
byId[comment.claim_id] = commentIds.filter(commentId => commentId !== comment_id); byId[claimId].splice(i, 1);
break;
delete commentById[comment_id]; }
} }
return _extends$7({}, state, { delete commentById[comment_id];
return _extends$8({}, state, {
commentById, commentById,
byId, byId,
isLoading: false isLoading: false
}); });
}, },
// do nothing // do nothing
[COMMENT_ABANDON_FAILED]: (state, action) => _extends$7({}, state, { [COMMENT_ABANDON_FAILED]: (state, action) => _extends$8({}, state, {
isLoading: false isLoading: false
}), }),
// do nothing // do nothing
[COMMENT_UPDATE_STARTED]: (state, action) => _extends$7({}, state, { [COMMENT_UPDATE_STARTED]: (state, action) => _extends$8({}, state, {
isLoading: true isLoading: true
}), }),
// replace existing comment with comment returned here under its comment_id // replace existing comment with comment returned here under its comment_id
@ -4780,24 +4788,24 @@ const commentReducer = handleActions({
commentById[comment.comment_id] = comment; commentById[comment.comment_id] = comment;
} }
return _extends$7({}, state, { return _extends$8({}, state, {
commentById, commentById,
isLoading: false isLoading: false
}); });
}, },
// nothing can be done here // nothing can be done here
[COMMENT_UPDATE_FAILED]: (state, action) => _extends$7({}, state, { [COMMENT_UPDATE_FAILED]: (state, action) => _extends$8({}, state, {
isLoading: false isLoading: false
}), }),
// nothing can really be done here // nothing can really be done here
[COMMENT_HIDE_STARTED]: (state, action) => _extends$7({}, state, { [COMMENT_HIDE_STARTED]: (state, action) => _extends$8({}, state, {
isLoading: true isLoading: true
}), }),
[COMMENT_HIDE_COMPLETED]: (state, action) => _extends$7({}, state, { // todo: add HiddenComments state & create selectors [COMMENT_HIDE_COMPLETED]: (state, action) => _extends$8({}, state, { // todo: add HiddenComments state & create selectors
isLoading: false isLoading: false
}), }),
// nothing can be done here // nothing can be done here
[COMMENT_HIDE_FAILED]: (state, action) => _extends$7({}, state, { [COMMENT_HIDE_FAILED]: (state, action) => _extends$8({}, state, {
isLoading: false isLoading: false
}) })
}, defaultState$1); }, defaultState$1);
@ -5638,7 +5646,7 @@ const walletReducer = handleActions({
}) })
}, defaultState$a); }, defaultState$a);
// //
const selectState$6 = state => state.content || {}; const selectState$6 = state => state.content || {};

View file

@ -142,7 +142,7 @@ declare type CommentHideResponse = {
declare type CommentAbandonResponse = { declare type CommentAbandonResponse = {
// keyed by the CommentId given // keyed by the CommentId given
[string]: { abandoned: boolean }, abandoned: boolean,
}; };
declare type ChannelListResponse = { declare type ChannelListResponse = {

2
flow-typed/Lbry.js vendored
View file

@ -142,7 +142,7 @@ declare type CommentHideResponse = {
declare type CommentAbandonResponse = { declare type CommentAbandonResponse = {
// keyed by the CommentId given // keyed by the CommentId given
[string]: { abandoned: boolean }, abandoned: boolean,
}; };
declare type ChannelListResponse = { declare type ChannelListResponse = {

View file

@ -122,13 +122,20 @@ export function doCommentAbandon(comment_id: string) {
comment_id: comment_id, comment_id: comment_id,
}) })
.then((result: CommentAbandonResponse) => { .then((result: CommentAbandonResponse) => {
dispatch({ // Comment may not be deleted if the signing channel can't be signed.
type: ACTIONS.COMMENT_ABANDON_COMPLETED, // This will happen if the channel was recently created or abandoned.
data: { if (result.abandoned) {
comment_id: comment_id, dispatch({
abandoned: result, type: ACTIONS.COMMENT_ABANDON_COMPLETED,
}, data: {
}); comment_id: comment_id,
},
});
} else {
dispatch({
type: ACTIONS.COMMENT_ABANDON_FAILED,
});
}
}) })
.catch(error => { .catch(error => {
dispatch({ dispatch({

View file

@ -85,20 +85,21 @@ export const commentReducer = handleActions(
...state, ...state,
isLoading: true, isLoading: true,
}), }),
// remove the existing comment from the id -> comment list and claim -> commentIds
[ACTIONS.COMMENT_ABANDON_COMPLETED]: (state: CommentsState, action: any) => { [ACTIONS.COMMENT_ABANDON_COMPLETED]: (state: CommentsState, action: any) => {
const { comment_id, abandoned } = action.data; const { comment_id } = action.data;
const commentById = Object.assign({}, state.commentById); const commentById = Object.assign({}, state.commentById);
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
if (abandoned && comment_id in abandoned) { // to remove the comment and its references
// messy but necessary for the time being const claimId = commentById[comment_id].claim_id;
const comment: Comment = commentById[comment_id]; for (let i = 0; i < byId[claimId].length; i++) {
const commentIds = byId[comment.claim_id]; if (byId[claimId][i] === comment_id) {
byId[comment.claim_id] = commentIds.filter(commentId => commentId !== comment_id); byId[claimId].splice(i, 1);
break;
delete commentById[comment_id]; }
} }
delete commentById[comment_id];
return { return {
...state, ...state,
commentById, commentById,