nfp_sites/filadelfia_archive/app/page_browse.js

63 lines
1.7 KiB
JavaScript
Raw Permalink 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-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.path_short].join('/'),
2023-11-29 19:19:41 +00:00
style: article.avif_preview ? `background-image: url('${article.avif_preview}')` : null,
}, [
m('span', lang.printdate(article.publish_at)),
2023-11-20 07:12:08 +00:00
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(-1).map(year => {
2023-11-20 07:12:08 +00:00
return [
m('.gallery-year', year.title),
this.mMonth(vnode, year),
]
})
: null
]),
2023-11-09 09:44:04 +00:00
]
},
}
module.exports = Browse