2018-02-09 01:51:48 +00:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { getLists } from '../_api/lists'
|
|
|
|
import { cacheFirstUpdateAfter } from '../_utils/sync'
|
2018-08-30 02:03:12 +00:00
|
|
|
import { database } from '../_database/database'
|
2018-02-09 01:51:48 +00:00
|
|
|
|
2018-12-05 08:21:54 +00:00
|
|
|
export async function updateListsForInstance (instanceName) {
|
|
|
|
let { loggedInInstances } = store.get()
|
|
|
|
let accessToken = loggedInInstances[instanceName].access_token
|
2018-02-09 01:51:48 +00:00
|
|
|
|
|
|
|
await cacheFirstUpdateAfter(
|
2018-12-05 08:21:54 +00:00
|
|
|
() => getLists(instanceName, accessToken),
|
|
|
|
() => database.getLists(instanceName),
|
|
|
|
lists => database.setLists(instanceName, lists),
|
2018-02-09 01:51:48 +00:00
|
|
|
lists => {
|
2018-04-19 16:37:05 +00:00
|
|
|
let { instanceLists } = store.get()
|
2018-12-05 08:21:54 +00:00
|
|
|
instanceLists[instanceName] = lists
|
2018-08-30 04:42:57 +00:00
|
|
|
store.set({ instanceLists: instanceLists })
|
2018-02-09 01:51:48 +00:00
|
|
|
}
|
|
|
|
)
|
2018-02-09 06:29:29 +00:00
|
|
|
}
|