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

41 lines
1.1 KiB
JavaScript

const m = require('mithril')
const videos = require('./videos')
const Authentication = require('./authentication')
const Menu = {
oninit: function(vnode) {
this.currentActive = 'home'
this.loading = false
this.onbeforeupdate()
},
onbeforeupdate: function() {
let currentPath = m.route.get()
/*if (currentPath === '/') this.currentActive = 'home'
else if (currentPath === '/login') this.currentActive = 'login'
else if (currentPath && currentPath.startsWith('/page')) this.currentActive = currentPath.slice(currentPath.lastIndexOf('/') + 1)*/
},
logOut: function() {
Authentication.clearToken()
m.route.set('/')
},
view: function() {
console.log(Authentication.currentUser)
return Authentication.currentUser
? [
m('nav', [
m('h4', m(m.route.Link, { href: '/browse' }, 'Filadelfia archival center')),
Authentication.currentUser.rank > 10
? m(m.route.Link, { class: 'upload', href: '/upload' }, 'Upload')
: null,
m('button.logout', { onclick: this.logOut }, 'Log out'),
])
]
: null
},
}
module.exports = Menu