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