Notes2/static/js/sync.mjs
Magnus Åhall ac8b334eee Rewrite
2024-12-03 06:53:31 +01:00

20 lines
486 B
JavaScript

import { API } from 'api'
export class Sync {
static async tree() {
let oldMax = 0
nodeStore.getAppState('latest_sync')
.then(state => {
if (state !== null) {
oldMax = state.value
return state.value
}
return 0
})
.then(sequence => API.query('POST', `/node/tree/${sequence}`, {}))
.then(res => nodeStore.updateTreeRecords(res.Nodes))
.then(newMax => nodeStore.setAppState('latest_sync', Math.max(oldMax, newMax)))
.catch(e => alert(e))
}
}