2018-02-09 01:51:48 +00:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { getLists } from '../_api/lists'
|
|
|
|
import { cacheFirstUpdateAfter } from '../_utils/sync'
|
2018-04-17 04:56:21 +01:00
|
|
|
import {
|
|
|
|
getLists as getListsFromDatabase,
|
|
|
|
setLists as setListsInDatabase
|
|
|
|
} from '../_database/meta'
|
2018-02-09 01:51:48 +00:00
|
|
|
|
2018-02-09 06:29:29 +00:00
|
|
|
export async function updateLists () {
|
2018-02-09 01:51:48 +00:00
|
|
|
let instanceName = store.get('currentInstance')
|
|
|
|
let accessToken = store.get('accessToken')
|
|
|
|
|
|
|
|
await cacheFirstUpdateAfter(
|
|
|
|
() => getLists(instanceName, accessToken),
|
2018-04-17 04:56:21 +01:00
|
|
|
() => getListsFromDatabase(instanceName),
|
|
|
|
lists => setListsInDatabase(instanceName, lists),
|
2018-02-09 01:51:48 +00:00
|
|
|
lists => {
|
|
|
|
let instanceLists = store.get('instanceLists')
|
|
|
|
instanceLists[instanceName] = lists
|
|
|
|
store.set({instanceLists: instanceLists})
|
|
|
|
}
|
|
|
|
)
|
2018-02-09 06:29:29 +00:00
|
|
|
}
|