mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
added like count to nodes
This commit is contained in:
parent
7f372bb025
commit
5c1610218d
6 changed files with 39 additions and 6 deletions
|
@ -280,16 +280,20 @@ function* onEditSaga({ id }: ReturnType<typeof nodeEdit>) {
|
|||
function* onLikeSaga({ id }: ReturnType<typeof nodeLike>) {
|
||||
const {
|
||||
current,
|
||||
current: { is_liked },
|
||||
current: { is_liked, like_count },
|
||||
} = yield select(selectNode);
|
||||
|
||||
yield call(updateNodeEverywhere, { ...current, is_liked: !is_liked });
|
||||
yield call(updateNodeEverywhere, {
|
||||
...current,
|
||||
is_liked: !is_liked,
|
||||
like_count: is_liked ? Math.max(like_count - 1, 0) : like_count + 1,
|
||||
});
|
||||
|
||||
const { data, error } = yield call(reqWrapper, postNodeLike, { id });
|
||||
|
||||
if (!error || data.is_liked === !is_liked) return; // ok and matches
|
||||
|
||||
yield call(updateNodeEverywhere, { ...current, is_liked });
|
||||
yield call(updateNodeEverywhere, { ...current, is_liked, like_count });
|
||||
}
|
||||
|
||||
function* onStarSaga({ id }: ReturnType<typeof nodeLike>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue