pinafore/routes/_actions/lists.js

20 lines
626 B
JavaScript
Raw Normal View History

import { store } from '../_store/store'
import { getLists } from '../_api/lists'
import { cacheFirstUpdateAfter } from '../_utils/sync'
import { database } from '../_database/database'
2018-02-09 06:29:29 +00:00
export async function updateLists () {
let { currentInstance, accessToken } = store.get()
await cacheFirstUpdateAfter(
() => getLists(currentInstance, accessToken),
() => database.getLists(currentInstance),
lists => database.setLists(currentInstance, lists),
lists => {
let { instanceLists } = store.get()
instanceLists[currentInstance] = lists
store.set({ instanceLists: instanceLists })
}
)
2018-02-09 06:29:29 +00:00
}