Corrects abandon return type & fixes issue where redux wasn't being changed
This commit is contained in:
parent
1e1fcb8b18
commit
bc2436dce2
5 changed files with 61 additions and 45 deletions
58
dist/bundle.es.js
vendored
58
dist/bundle.es.js
vendored
|
@ -4204,13 +4204,20 @@ function doCommentAbandon(comment_id) {
|
|||
return lbryProxy.comment_abandon({
|
||||
comment_id: comment_id
|
||||
}).then(result => {
|
||||
dispatch({
|
||||
type: COMMENT_ABANDON_COMPLETED,
|
||||
data: {
|
||||
comment_id: comment_id,
|
||||
abandoned: result
|
||||
}
|
||||
});
|
||||
// Comment may not be deleted if the signing channel can't be signed.
|
||||
// This will happen if the channel was recently created or abandoned.
|
||||
if (result.abandoned) {
|
||||
dispatch({
|
||||
type: COMMENT_ABANDON_COMPLETED,
|
||||
data: {
|
||||
comment_id: comment_id
|
||||
}
|
||||
});
|
||||
} else {
|
||||
dispatch({
|
||||
type: COMMENT_ABANDON_FAILED
|
||||
});
|
||||
}
|
||||
}).catch(error => {
|
||||
dispatch({
|
||||
type: COMMENT_ABANDON_FAILED,
|
||||
|
@ -4740,35 +4747,36 @@ const commentReducer = handleActions({
|
|||
[COMMENT_LIST_FAILED]: (state, action) => _extends$8({}, state, {
|
||||
isLoading: false
|
||||
}),
|
||||
[COMMENT_ABANDON_STARTED]: (state, action) => _extends$7({}, state, {
|
||||
[COMMENT_ABANDON_STARTED]: (state, action) => _extends$8({}, state, {
|
||||
isLoading: true
|
||||
}),
|
||||
// remove the existing comment from the id -> comment list and claim -> commentIds
|
||||
[COMMENT_ABANDON_COMPLETED]: (state, action) => {
|
||||
const { comment_id, abandoned } = action.data;
|
||||
const { comment_id } = action.data;
|
||||
const commentById = Object.assign({}, state.commentById);
|
||||
const byId = Object.assign({}, state.byId);
|
||||
|
||||
if (abandoned && comment_id in abandoned) {
|
||||
// messy but necessary for the time being
|
||||
const comment = commentById[comment_id];
|
||||
const commentIds = byId[comment.claim_id];
|
||||
byId[comment.claim_id] = commentIds.filter(commentId => commentId !== comment_id);
|
||||
|
||||
delete commentById[comment_id];
|
||||
// to remove the comment and its references
|
||||
const claimId = commentById[comment_id].claim_id;
|
||||
for (let i = 0; i < byId[claimId].length; i++) {
|
||||
if (byId[claimId][i] === comment_id) {
|
||||
byId[claimId].splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return _extends$7({}, state, {
|
||||
delete commentById[comment_id];
|
||||
|
||||
return _extends$8({}, state, {
|
||||
commentById,
|
||||
byId,
|
||||
isLoading: false
|
||||
});
|
||||
},
|
||||
// do nothing
|
||||
[COMMENT_ABANDON_FAILED]: (state, action) => _extends$7({}, state, {
|
||||
[COMMENT_ABANDON_FAILED]: (state, action) => _extends$8({}, state, {
|
||||
isLoading: false
|
||||
}),
|
||||
// do nothing
|
||||
[COMMENT_UPDATE_STARTED]: (state, action) => _extends$7({}, state, {
|
||||
[COMMENT_UPDATE_STARTED]: (state, action) => _extends$8({}, state, {
|
||||
isLoading: true
|
||||
}),
|
||||
// replace existing comment with comment returned here under its comment_id
|
||||
|
@ -4780,24 +4788,24 @@ const commentReducer = handleActions({
|
|||
commentById[comment.comment_id] = comment;
|
||||
}
|
||||
|
||||
return _extends$7({}, state, {
|
||||
return _extends$8({}, state, {
|
||||
commentById,
|
||||
isLoading: false
|
||||
});
|
||||
},
|
||||
// nothing can be done here
|
||||
[COMMENT_UPDATE_FAILED]: (state, action) => _extends$7({}, state, {
|
||||
[COMMENT_UPDATE_FAILED]: (state, action) => _extends$8({}, state, {
|
||||
isLoading: false
|
||||
}),
|
||||
// nothing can really be done here
|
||||
[COMMENT_HIDE_STARTED]: (state, action) => _extends$7({}, state, {
|
||||
[COMMENT_HIDE_STARTED]: (state, action) => _extends$8({}, state, {
|
||||
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
|
||||
}),
|
||||
// nothing can be done here
|
||||
[COMMENT_HIDE_FAILED]: (state, action) => _extends$7({}, state, {
|
||||
[COMMENT_HIDE_FAILED]: (state, action) => _extends$8({}, state, {
|
||||
isLoading: false
|
||||
})
|
||||
}, defaultState$1);
|
||||
|
|
2
dist/flow-typed/Lbry.js
vendored
2
dist/flow-typed/Lbry.js
vendored
|
@ -142,7 +142,7 @@ declare type CommentHideResponse = {
|
|||
|
||||
declare type CommentAbandonResponse = {
|
||||
// keyed by the CommentId given
|
||||
[string]: { abandoned: boolean },
|
||||
abandoned: boolean,
|
||||
};
|
||||
|
||||
declare type ChannelListResponse = {
|
||||
|
|
2
flow-typed/Lbry.js
vendored
2
flow-typed/Lbry.js
vendored
|
@ -142,7 +142,7 @@ declare type CommentHideResponse = {
|
|||
|
||||
declare type CommentAbandonResponse = {
|
||||
// keyed by the CommentId given
|
||||
[string]: { abandoned: boolean },
|
||||
abandoned: boolean,
|
||||
};
|
||||
|
||||
declare type ChannelListResponse = {
|
||||
|
|
|
@ -122,13 +122,20 @@ export function doCommentAbandon(comment_id: string) {
|
|||
comment_id: comment_id,
|
||||
})
|
||||
.then((result: CommentAbandonResponse) => {
|
||||
dispatch({
|
||||
type: ACTIONS.COMMENT_ABANDON_COMPLETED,
|
||||
data: {
|
||||
comment_id: comment_id,
|
||||
abandoned: result,
|
||||
},
|
||||
});
|
||||
// Comment may not be deleted if the signing channel can't be signed.
|
||||
// This will happen if the channel was recently created or abandoned.
|
||||
if (result.abandoned) {
|
||||
dispatch({
|
||||
type: ACTIONS.COMMENT_ABANDON_COMPLETED,
|
||||
data: {
|
||||
comment_id: comment_id,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
dispatch({
|
||||
type: ACTIONS.COMMENT_ABANDON_FAILED,
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
dispatch({
|
||||
|
|
|
@ -85,20 +85,21 @@ export const commentReducer = handleActions(
|
|||
...state,
|
||||
isLoading: true,
|
||||
}),
|
||||
// remove the existing comment from the id -> comment list and claim -> commentIds
|
||||
[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 byId = Object.assign({}, state.byId);
|
||||
|
||||
if (abandoned && comment_id in abandoned) {
|
||||
// messy but necessary for the time being
|
||||
const comment: Comment = commentById[comment_id];
|
||||
const commentIds = byId[comment.claim_id];
|
||||
byId[comment.claim_id] = commentIds.filter(commentId => commentId !== comment_id);
|
||||
|
||||
delete commentById[comment_id];
|
||||
// to remove the comment and its references
|
||||
const claimId = commentById[comment_id].claim_id;
|
||||
for (let i = 0; i < byId[claimId].length; i++) {
|
||||
if (byId[claimId][i] === comment_id) {
|
||||
byId[claimId].splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete commentById[comment_id];
|
||||
|
||||
return {
|
||||
...state,
|
||||
commentById,
|
||||
|
|
Loading…
Reference in a new issue