dismiss read articles on refresh #94

This commit is contained in:
刘浩远 2020-11-24 16:11:22 +08:00
parent 7a286de5aa
commit 58e32f9985
2 changed files with 40 additions and 2 deletions

View File

@ -115,6 +115,7 @@ export type FeedState = {
export const INIT_FEEDS = "INIT_FEEDS"
export const INIT_FEED = "INIT_FEED"
export const LOAD_MORE = "LOAD_MORE"
export const DISMISS_ITEMS = "DISMISS_ITEMS"
interface initFeedsAction {
type: typeof INIT_FEEDS
@ -137,7 +138,34 @@ interface loadMoreAction {
err?
}
interface dismissItemsAction{
type: typeof DISMISS_ITEMS
fid: string
iids: Set<number>
}
export type FeedActionTypes = initFeedAction | initFeedsAction | loadMoreAction
| dismissItemsAction
export function dismissItems(): AppThunk {
return (dispatch, getState) => {
const state = getState()
let fid = state.page.feedId
let filter = state.feeds[fid].filter
let iids = new Set<number>()
for (let iid of state.feeds[fid].iids) {
let item = state.items[iid]
if (!FeedFilter.testItem(filter, item)) {
iids.add(iid)
}
}
dispatch({
type: DISMISS_ITEMS,
fid: fid,
iids: iids
})
}
}
export function initFeedsRequest(): FeedActionTypes {
return {
@ -293,6 +321,14 @@ export function feedReducer(
}
default: return state
}
case DISMISS_ITEMS:
let nextState = { ...state }
let feed = state[action.fid]
nextState[action.fid] = {
...feed,
iids: feed.iids.filter(iid => !action.iids.has(iid))
}
return nextState
case INIT_FEED:
switch (action.status) {
case ActionStatus.Success: return {

View File

@ -3,7 +3,7 @@ import lf from "lovefield"
import intl from "react-intl-universal"
import { domParser, htmlDecode, ActionStatus, AppThunk, platformCtrl } from "../utils"
import { RSSSource, updateSource, updateUnreadCounts } from "./source"
import { FeedActionTypes, INIT_FEED, LOAD_MORE, FilterType, initFeeds } from "./feed"
import { FeedActionTypes, INIT_FEED, LOAD_MORE, FilterType, initFeeds, dismissItems } from "./feed"
import Parser from "@yang991178/rss-parser"
import { pushNotification, setupAutoFetch, SettingsActionTypes, FREE_MEMORY } from "./app"
import { getServiceHooks, syncWithService, ServiceActionTypes, SYNC_LOCAL_ITEMS } from "./service"
@ -213,6 +213,8 @@ export function fetchItems(background = false, sids: number[] = null): AppThunk<
if (inserted.length > 0) {
window.utils.requestAttention()
}
} else {
dispatch(dismissItems())
}
dispatch(setupAutoFetch())
})