Skip to content

Commit

Permalink
GS-10658 Update saving posts logic (#2405)
Browse files Browse the repository at this point in the history
Co-authored-by: nickdpicnic <[email protected]>
  • Loading branch information
2 people authored and github-actions[bot] committed Dec 8, 2023
1 parent 239647a commit d8656b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class CommentChatPresentationModel implements CommentChatViewModel {
);

CommentChatPresentationModel byUpdatingSavedStatus({required bool saved}) => copyWith(
feedPost: feedPost.copyWith(context: feedPost.context.copyWith(saved: saved)),
feedPost: feedPost.byUpdatingSavedStatus(iSaved: saved),
);

CommentChatPresentationModel byUpdatingAuthorWithFollow({required bool follow}) {
Expand Down
18 changes: 15 additions & 3 deletions lib/features/posts/comment_chat/comment_chat_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,31 @@ class CommentChatPresenter extends Cubit<CommentChatViewModel> with Subscription
target: AnalyticsTapTarget.postBookmarkButton,
),
);

final previousState = _model.feedPost.context.saved;

void emitStatus({required bool saved}) {
_emitAndNotify(_model.byUpdatingSavedStatus(saved: saved));
_model.onPostUpdatedCallback?.call(_model.feedPost);
}

emitStatus(saved: !previousState);

_savePostToCollectionUseCase
.execute(
input: SavePostInput(
postId: _model.feedPost.id,
save: !_model.feedPost.context.saved,
save: !previousState,
),
)
.observeStatusChanges(
(result) => tryEmit(_model.copyWith(savingPostResult: result)),
)
.doOn(
success: (post) => tryEmit(_model.byUpdatingSavedStatus(saved: post.context.saved)),
fail: (fail) => navigator.showError(fail.displayableFailure()),
success: (post) {
emitStatus(saved: post.context.saved);
},
fail: (fail) => emitStatus(saved: previousState),
);
}

Expand Down

0 comments on commit d8656b8

Please sign in to comment.