mirror of
https://github.com/yang991178/fluent-reader.git
synced 2025-01-30 17:15:20 +01:00
dismiss read articles on refresh #94
This commit is contained in:
parent
7a286de5aa
commit
58e32f9985
@ -115,6 +115,7 @@ export type FeedState = {
|
|||||||
export const INIT_FEEDS = "INIT_FEEDS"
|
export const INIT_FEEDS = "INIT_FEEDS"
|
||||||
export const INIT_FEED = "INIT_FEED"
|
export const INIT_FEED = "INIT_FEED"
|
||||||
export const LOAD_MORE = "LOAD_MORE"
|
export const LOAD_MORE = "LOAD_MORE"
|
||||||
|
export const DISMISS_ITEMS = "DISMISS_ITEMS"
|
||||||
|
|
||||||
interface initFeedsAction {
|
interface initFeedsAction {
|
||||||
type: typeof INIT_FEEDS
|
type: typeof INIT_FEEDS
|
||||||
@ -137,7 +138,34 @@ interface loadMoreAction {
|
|||||||
err?
|
err?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface dismissItemsAction{
|
||||||
|
type: typeof DISMISS_ITEMS
|
||||||
|
fid: string
|
||||||
|
iids: Set<number>
|
||||||
|
}
|
||||||
|
|
||||||
export type FeedActionTypes = initFeedAction | initFeedsAction | loadMoreAction
|
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 {
|
export function initFeedsRequest(): FeedActionTypes {
|
||||||
return {
|
return {
|
||||||
@ -293,6 +321,14 @@ export function feedReducer(
|
|||||||
}
|
}
|
||||||
default: return state
|
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:
|
case INIT_FEED:
|
||||||
switch (action.status) {
|
switch (action.status) {
|
||||||
case ActionStatus.Success: return {
|
case ActionStatus.Success: return {
|
||||||
|
@ -3,7 +3,7 @@ import lf from "lovefield"
|
|||||||
import intl from "react-intl-universal"
|
import intl from "react-intl-universal"
|
||||||
import { domParser, htmlDecode, ActionStatus, AppThunk, platformCtrl } from "../utils"
|
import { domParser, htmlDecode, ActionStatus, AppThunk, platformCtrl } from "../utils"
|
||||||
import { RSSSource, updateSource, updateUnreadCounts } from "./source"
|
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 Parser from "@yang991178/rss-parser"
|
||||||
import { pushNotification, setupAutoFetch, SettingsActionTypes, FREE_MEMORY } from "./app"
|
import { pushNotification, setupAutoFetch, SettingsActionTypes, FREE_MEMORY } from "./app"
|
||||||
import { getServiceHooks, syncWithService, ServiceActionTypes, SYNC_LOCAL_ITEMS } from "./service"
|
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) {
|
if (inserted.length > 0) {
|
||||||
window.utils.requestAttention()
|
window.utils.requestAttention()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
dispatch(dismissItems())
|
||||||
}
|
}
|
||||||
dispatch(setupAutoFetch())
|
dispatch(setupAutoFetch())
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user