2020-06-11 11:45:46 +02:00
|
|
|
import { connect } from "react-redux"
|
2021-08-21 23:49:56 +02:00
|
|
|
import {
|
|
|
|
initIntl,
|
|
|
|
saveSettings,
|
|
|
|
setupAutoFetch,
|
|
|
|
} from "../../scripts/models/app"
|
2020-06-15 08:16:49 +02:00
|
|
|
import * as db from "../../scripts/db"
|
2020-06-11 11:45:46 +02:00
|
|
|
import AppTab from "../../components/settings/app"
|
2020-06-30 09:29:39 +02:00
|
|
|
import { importAll } from "../../scripts/settings"
|
2020-08-25 04:03:39 +02:00
|
|
|
import { updateUnreadCounts } from "../../scripts/models/source"
|
|
|
|
import { AppDispatch } from "../../scripts/utils"
|
2020-06-11 11:45:46 +02:00
|
|
|
|
2020-08-25 04:03:39 +02:00
|
|
|
const mapDispatchToProps = (dispatch: AppDispatch) => ({
|
2020-06-11 11:45:46 +02:00
|
|
|
setLanguage: (option: string) => {
|
2020-06-29 13:17:33 +02:00
|
|
|
window.settings.setLocaleSettings(option)
|
2020-06-11 11:45:46 +02:00
|
|
|
dispatch(initIntl())
|
2020-06-15 08:16:49 +02:00
|
|
|
},
|
2020-07-10 06:56:58 +02:00
|
|
|
setFetchInterval: (interval: number) => {
|
|
|
|
window.settings.setFetchInterval(interval)
|
2020-07-09 11:59:25 +02:00
|
|
|
dispatch(setupAutoFetch())
|
|
|
|
},
|
2020-08-31 09:59:39 +02:00
|
|
|
deleteArticles: async (days: number) => {
|
2020-06-15 08:16:49 +02:00
|
|
|
dispatch(saveSettings())
|
|
|
|
let date = new Date()
|
|
|
|
date.setTime(date.getTime() - days * 86400000)
|
2021-08-21 23:49:56 +02:00
|
|
|
await db.itemsDB
|
|
|
|
.delete()
|
|
|
|
.from(db.items)
|
|
|
|
.where(db.items.date.lt(date))
|
|
|
|
.exec()
|
2020-08-31 09:59:39 +02:00
|
|
|
await dispatch(updateUnreadCounts())
|
|
|
|
dispatch(saveSettings())
|
|
|
|
},
|
2020-06-30 09:29:39 +02:00
|
|
|
importAll: async () => {
|
|
|
|
dispatch(saveSettings())
|
2021-08-21 23:49:56 +02:00
|
|
|
let cancelled = await importAll()
|
2020-06-30 09:29:39 +02:00
|
|
|
if (cancelled) dispatch(saveSettings())
|
2021-08-21 23:49:56 +02:00
|
|
|
},
|
2020-06-11 11:45:46 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
const AppTabContainer = connect(null, mapDispatchToProps)(AppTab)
|
2021-08-21 23:49:56 +02:00
|
|
|
export default AppTabContainer
|