const html = require('choo/html')
const _ = require('lodash')
module.exports = view
function view (state, emit) {
return html`
${state.library.map(listZines)}
`
function listZines (zine) {
var collection = state.params.collection
// This could likely be muuuch prettier, need to refactor!
var isPartOfCollection = () => {
if (zine.collections) {
var name = decodeURI(collection)
return zine.collections.find(collection => _.toLower(collection) === name)
} else return false
}
if (collection && !isPartOfCollection()) {
return //nothing
} else {
var trimmedUrl = _.trimEnd(zine.url, '/')
var zineID = zine.title.replace(/ /g, '-')
var imagePath = state.covers[trimmedUrl]
return html`
${zine.title}
${zine.notes}
${renderInfo(zine, state)}
`
}
}
function renderInfo (zine, state) {
var trimmedUrl = _.trimEnd(zine.url, '/')
var info = _.entries(state.info[trimmedUrl])
if (info) {
return html`
Info From Zine
${info.map(pair => {
return html`
${pair[0]}: ${pair[1]}
`
})
}
`
}
}
}