From 4e842e642037b761a6b02983a4d99f695effa929 Mon Sep 17 00:00:00 2001 From: Bruce Liu Date: Wed, 15 Dec 2021 14:39:11 +0800 Subject: [PATCH] fix negative unread counts #216 --- src/scripts/models/item.ts | 6 ++++-- src/scripts/models/source.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/scripts/models/item.ts b/src/scripts/models/item.ts index fbe7df8..5eca66c 100644 --- a/src/scripts/models/item.ts +++ b/src/scripts/models/item.ts @@ -312,7 +312,8 @@ const markUnreadDone = (item: RSSItem): ItemActionTypes => ({ }) export function markRead(item: RSSItem): AppThunk { - return dispatch => { + return (dispatch, getState) => { + item = getState().items[item._id] if (!item.hasRead) { db.itemsDB .update(db.items) @@ -377,7 +378,8 @@ export function markAllRead( } export function markUnread(item: RSSItem): AppThunk { - return dispatch => { + return (dispatch, getState) => { + item = getState().items[item._id] if (item.hasRead) { db.itemsDB .update(db.items) diff --git a/src/scripts/models/source.ts b/src/scripts/models/source.ts index f44a547..85c5c06 100644 --- a/src/scripts/models/source.ts +++ b/src/scripts/models/source.ts @@ -483,7 +483,7 @@ export function sourceReducer( } case MARK_ALL_READ: { let nextState = { ...state } - action.sids.map((sid, i) => { + action.sids.forEach((sid) => { nextState[sid] = { ...state[sid], unreadCount: action.time ? state[sid].unreadCount : 0,