update group context menu
This commit is contained in:
parent
7141be86ad
commit
920a37c452
|
@ -30,8 +30,9 @@ export type ContextMenuProps = ContextReduxProps & {
|
|||
setViewConfigs: (configs: ViewConfigs) => void
|
||||
switchFilter: (filter: FilterType) => void
|
||||
toggleFilter: (filter: FilterType) => void
|
||||
markAllRead: (sids: number[], date?: Date, before?: boolean) => void
|
||||
settings: () => void
|
||||
markAllRead: (sids: number[], date?: Date, before?: boolean) => void
|
||||
fetchItems: (sids: number[]) => void
|
||||
settings: (sids: number[]) => void
|
||||
close: () => void
|
||||
}
|
||||
|
||||
|
@ -359,11 +360,17 @@ export class ContextMenu extends React.Component<ContextMenuProps> {
|
|||
iconProps: { iconName: "CheckMark" },
|
||||
onClick: () => this.props.markAllRead(this.props.sids)
|
||||
},
|
||||
{
|
||||
key: "refresh",
|
||||
text: intl.get("nav.refresh"),
|
||||
iconProps: { iconName: "Sync" },
|
||||
onClick: () => this.props.fetchItems(this.props.sids)
|
||||
},
|
||||
{
|
||||
key: "manage",
|
||||
text: intl.get("context.manageSources"),
|
||||
iconProps: { iconName: "Settings" },
|
||||
onClick: this.props.settings
|
||||
onClick: () => this.props.settings(this.props.sids)
|
||||
}
|
||||
]
|
||||
default: return []
|
||||
|
|
|
@ -10,6 +10,8 @@ import DangerButton from "../utils/danger-button"
|
|||
type SourcesTabProps = {
|
||||
sources: SourceState
|
||||
serviceOn: boolean
|
||||
sids: number[]
|
||||
acknowledgeSIDs: () => void
|
||||
addSource: (url: string) => void
|
||||
updateSourceName: (source: RSSSource, name: string) => void
|
||||
updateSourceIcon: (source: RSSSource, iconUrl: string) => Promise<void>
|
||||
|
@ -61,6 +63,15 @@ class SourcesTab extends React.Component<SourcesTabProps, SourcesTabState> {
|
|||
})
|
||||
}
|
||||
|
||||
componentDidMount = () => {
|
||||
if (this.props.sids.length > 0) {
|
||||
for (let sid of this.props.sids) {
|
||||
this.selection.setKeySelected(String(sid), true, false)
|
||||
}
|
||||
this.props.acknowledgeSIDs()
|
||||
}
|
||||
}
|
||||
|
||||
columns = (): IColumn[] => [
|
||||
{
|
||||
key: "favicon",
|
||||
|
|
|
@ -3,7 +3,7 @@ import { createSelector } from "reselect"
|
|||
import { RootState } from "../scripts/reducer"
|
||||
import { ContextMenuType, closeContextMenu, toggleSettings } from "../scripts/models/app"
|
||||
import { ContextMenu } from "../components/context-menu"
|
||||
import { RSSItem, markRead, markUnread, toggleStarred, toggleHidden, markAllRead } from "../scripts/models/item"
|
||||
import { RSSItem, markRead, markUnread, toggleStarred, toggleHidden, markAllRead, fetchItems } from "../scripts/models/item"
|
||||
import { showItem, switchView, switchFilter, toggleFilter, setViewConfigs } from "../scripts/models/page"
|
||||
import { ViewType, ViewConfigs } from "../schema-types"
|
||||
import { FilterType } from "../scripts/models/feed"
|
||||
|
@ -73,7 +73,8 @@ const mapDispatchToProps = dispatch => {
|
|||
markAllRead: (sids: number[], date?: Date, before?: boolean) => {
|
||||
dispatch(markAllRead(sids, date, before))
|
||||
},
|
||||
settings: () => dispatch(toggleSettings()),
|
||||
fetchItems: (sids: number[]) => dispatch(fetchItems(false, sids)),
|
||||
settings: (sids: number[]) => dispatch(toggleSettings(true, sids)),
|
||||
close: () => dispatch(closeContextMenu())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,11 @@ import { connect } from "react-redux"
|
|||
import { initIntl, saveSettings, setupAutoFetch } from "../../scripts/models/app"
|
||||
import * as db from "../../scripts/db"
|
||||
import AppTab from "../../components/settings/app"
|
||||
import { initFeeds } from "../../scripts/models/feed"
|
||||
import { importAll } from "../../scripts/settings"
|
||||
import { updateUnreadCounts } from "../../scripts/models/source"
|
||||
import { AppDispatch } from "../../scripts/utils"
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
const mapDispatchToProps = (dispatch: AppDispatch) => ({
|
||||
setLanguage: (option: string) => {
|
||||
window.settings.setLocaleSettings(option)
|
||||
dispatch(initIntl())
|
||||
|
@ -19,10 +20,8 @@ const mapDispatchToProps = dispatch => ({
|
|||
let date = new Date()
|
||||
date.setTime(date.getTime() - days * 86400000)
|
||||
db.idb.remove({ date: { $lt: date } }, { multi: true }, () => {
|
||||
dispatch(initFeeds(true)).then(() => dispatch(saveSettings()))
|
||||
db.idb.prependOnceListener("compaction.done", () => {
|
||||
resolve()
|
||||
})
|
||||
dispatch(updateUnreadCounts()).then(() => dispatch(saveSettings()))
|
||||
db.idb.prependOnceListener("compaction.done", resolve)
|
||||
db.idb.persistence.compactDatafile()
|
||||
})
|
||||
}),
|
||||
|
|
|
@ -6,22 +6,25 @@ import SourcesTab from "../../components/settings/sources"
|
|||
import { addSource, RSSSource, updateSource, deleteSource, SourceOpenTarget, deleteSources } from "../../scripts/models/source"
|
||||
import { importOPML, exportOPML } from "../../scripts/models/group"
|
||||
import { AppDispatch, validateFavicon } from "../../scripts/utils"
|
||||
import { saveSettings } from "../../scripts/models/app"
|
||||
import { saveSettings, toggleSettings } from "../../scripts/models/app"
|
||||
import { SyncService } from "../../schema-types"
|
||||
|
||||
const getSources = (state: RootState) => state.sources
|
||||
const getServiceOn = (state: RootState) => state.service.type !== SyncService.None
|
||||
const getSIDs = (state: RootState) => state.app.settings.sids
|
||||
|
||||
const mapStateToProps = createSelector(
|
||||
[getSources, getServiceOn],
|
||||
(sources, serviceOn) => ({
|
||||
[getSources, getServiceOn, getSIDs],
|
||||
(sources, serviceOn, sids) => ({
|
||||
sources: sources,
|
||||
serviceOn: serviceOn
|
||||
serviceOn: serviceOn,
|
||||
sids: sids,
|
||||
})
|
||||
)
|
||||
|
||||
const mapDispatchToProps = (dispatch: AppDispatch) => {
|
||||
return {
|
||||
acknowledgeSIDs: () => dispatch(toggleSettings(true)),
|
||||
addSource: (url: string) => dispatch(addSource(url)),
|
||||
updateSourceName: (source: RSSSource, name: string) => {
|
||||
dispatch(updateSource({ ...source, name: name } as RSSSource))
|
||||
|
|
|
@ -49,6 +49,7 @@ export class AppState {
|
|||
settings = {
|
||||
display: false,
|
||||
changed: false,
|
||||
sids: new Array<number>(),
|
||||
saving: false
|
||||
}
|
||||
logMenu = {
|
||||
|
@ -136,9 +137,15 @@ export interface MenuActionTypes {
|
|||
export const TOGGLE_SETTINGS = "TOGGLE_SETTINGS"
|
||||
export const SAVE_SETTINGS = "SAVE_SETTINGS"
|
||||
|
||||
export interface SettingsActionTypes {
|
||||
type: typeof TOGGLE_SETTINGS | typeof SAVE_SETTINGS
|
||||
interface ToggleSettingsAction {
|
||||
type: typeof TOGGLE_SETTINGS
|
||||
open: boolean
|
||||
sids: number[]
|
||||
}
|
||||
interface SaveSettingsAction {
|
||||
type: typeof SAVE_SETTINGS
|
||||
}
|
||||
export type SettingsActionTypes = ToggleSettingsAction | SaveSettingsAction
|
||||
|
||||
export function closeContextMenu(): AppThunk {
|
||||
return (dispatch, getState) => {
|
||||
|
@ -190,9 +197,14 @@ export function toggleMenu(): AppThunk {
|
|||
}
|
||||
|
||||
export const toggleLogMenu = () => ({ type: TOGGLE_LOGS })
|
||||
export const toggleSettings = () => ({ type: TOGGLE_SETTINGS })
|
||||
export const saveSettings = () => ({ type: SAVE_SETTINGS })
|
||||
|
||||
export const toggleSettings = (open = true, sids = new Array<number>()) => ({
|
||||
type: TOGGLE_SETTINGS,
|
||||
open: open,
|
||||
sids: sids,
|
||||
})
|
||||
|
||||
export function exitSettings(): AppThunk {
|
||||
return (dispatch, getState) => {
|
||||
if (!getState().app.settings.saving) {
|
||||
|
@ -200,10 +212,10 @@ export function exitSettings(): AppThunk {
|
|||
dispatch(saveSettings())
|
||||
dispatch(selectAllArticles(true))
|
||||
dispatch(initFeeds(true)).then(() =>
|
||||
dispatch(toggleSettings())
|
||||
dispatch(toggleSettings(false))
|
||||
)
|
||||
} else {
|
||||
dispatch(toggleSettings())
|
||||
dispatch(toggleSettings(false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -493,8 +505,9 @@ export function appReducer(
|
|||
case TOGGLE_SETTINGS: return {
|
||||
...state,
|
||||
settings: {
|
||||
display: !state.settings.display,
|
||||
display: action.open,
|
||||
changed: false,
|
||||
sids: action.sids,
|
||||
saving: false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,17 +172,21 @@ export function insertItems(items: RSSItem[]): Promise<RSSItem[]> {
|
|||
})
|
||||
}
|
||||
|
||||
export function fetchItems(background = false): AppThunk<Promise<void>> {
|
||||
export function fetchItems(background = false, sids: number[] = null): AppThunk<Promise<void>> {
|
||||
return async (dispatch, getState) => {
|
||||
let promises = new Array<Promise<RSSItem[]>>()
|
||||
const initState = getState()
|
||||
if (!initState.app.fetchingItems && !initState.app.syncing) {
|
||||
await dispatch(syncWithService(background))
|
||||
if (sids === null || sids.filter(sid => initState.sources[sid].serviceRef !== undefined).length > 0)
|
||||
await dispatch(syncWithService(background))
|
||||
let timenow = new Date().getTime()
|
||||
let sources = <RSSSource[]>Object.values(getState().sources).filter(s => {
|
||||
let last = s.lastFetched ? s.lastFetched.getTime() : 0
|
||||
return !s.serviceRef && ((last > timenow) || (last + (s.fetchFrequency || 0) * 60000 <= timenow))
|
||||
})
|
||||
const sourcesState = getState().sources
|
||||
let sources = (sids === null)
|
||||
? Object.values(sourcesState).filter(s => {
|
||||
let last = s.lastFetched ? s.lastFetched.getTime() : 0
|
||||
return !s.serviceRef && ((last > timenow) || (last + (s.fetchFrequency || 0) * 60000 <= timenow))
|
||||
})
|
||||
: sids.map(sid => sourcesState[sid]).filter(s => !s.serviceRef)
|
||||
for (let source of sources) {
|
||||
let promise = RSSSource.fetchItems(source)
|
||||
promise.finally(() => dispatch(fetchItemsIntermediate()))
|
||||
|
|
Loading…
Reference in New Issue