nfp_sites/filadelfia_web/app/page_browse.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-11-09 09:44:04 +00:00
const m = require('mithril')
2023-11-20 07:12:08 +00:00
const api = require('./api')
2023-11-09 09:44:04 +00:00
const Authentication = require('./authentication')
const videos = require('./videos')
2023-11-20 07:12:08 +00:00
const lang = require('./lang')
2023-11-09 09:44:04 +00:00
const Browse = {
oninit: function(vnode) {
2023-11-14 07:27:04 +00:00
Authentication.requiresLogin()
2023-11-09 09:44:04 +00:00
},
2023-11-20 07:12:08 +00:00
mArticles: function(vnode, articles) {
return articles.map(article => {
2023-11-29 19:19:41 +00:00
return m(m.route.Link, {
href: ['', article.publish_at.getFullYear(), article.publish_at.getMonth() + 1, article.id].join('/'),
style: article.avif_preview ? `background-image: url('${article.avif_preview}')` : null,
}, [
2023-11-20 07:12:08 +00:00
m('span', article.publish_at.toUTCString()),
m('span', article.name),
])
})
},
mMonth: function(vnode, year) {
return year.branches.map(month => {
return [
m('.gallery-month', lang.months[month.title]),
m('.group', this.mArticles(vnode, month.videos))
]
})
2023-11-09 09:44:04 +00:00
},
view: function(vnode) {
2023-11-20 07:12:08 +00:00
let articles = videos.month?.videos || videos.year?.videos || videos.Articles
2023-11-09 09:44:04 +00:00
return [
2023-11-20 07:12:08 +00:00
api.loading ? m('div.loading-spinner') : null,
2023-11-09 09:44:04 +00:00
videos.error
2023-11-20 07:12:08 +00:00
? m('div.full-error', { onclick: videos.refreshTree }, [
2023-11-09 09:44:04 +00:00
videos.error, m('br'), 'Click here to try again'
])
: null,
2023-11-20 07:12:08 +00:00
m('.gallery', [
videos.month
? m('.group', this.mArticles(vnode, articles))
: null,
videos.year && !videos.month
? this.mMonth(vnode, videos.year)
: null,
!videos.year
? videos.Tree.slice(-2).map(year => {
return [
m('.gallery-year', year.title),
this.mMonth(vnode, year),
]
})
: null
]),
2023-11-09 09:44:04 +00:00
]
},
}
module.exports = Browse