35 lines
642 B
JavaScript
35 lines
642 B
JavaScript
|
const m = require('mithril')
|
||
|
const api = require('./api')
|
||
|
|
||
|
const Tree = []
|
||
|
|
||
|
exports.Tree = Tree
|
||
|
|
||
|
exports.loading = false
|
||
|
exports.error = ''
|
||
|
|
||
|
exports.refreshTree = function() {
|
||
|
exports.error = ''
|
||
|
|
||
|
if (exports.loading) return Promise.resolve()
|
||
|
|
||
|
exports.loading = true
|
||
|
|
||
|
m.redraw()
|
||
|
|
||
|
return api.sendRequest({
|
||
|
method: 'GET',
|
||
|
url: '/api/videos',
|
||
|
})
|
||
|
.then(pages => {
|
||
|
console.log(pages)
|
||
|
Tree.splice(0, Tree.length)
|
||
|
Tree.push.apply(Tree, pages.videos)
|
||
|
exports.loading = false
|
||
|
m.redraw()
|
||
|
}, err => {
|
||
|
exports.loading = false
|
||
|
m.redraw()
|
||
|
exports.error = 'Error fetching videos: ' + err.message
|
||
|
})
|
||
|
}
|