nfp_sites/filadelfia_web/app/videos.js
2023-11-09 09:45:37 +00:00

35 lines
No EOL
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
})
}