2019-06-27 20:36:43 +00:00
|
|
|
const {
|
|
|
|
a,
|
|
|
|
abbr,
|
2019-06-29 17:55:43 +00:00
|
|
|
div,
|
2019-06-27 20:36:43 +00:00
|
|
|
header,
|
|
|
|
img,
|
|
|
|
section,
|
|
|
|
article,
|
|
|
|
span,
|
|
|
|
form,
|
|
|
|
button,
|
|
|
|
footer
|
|
|
|
} = require('hyperaxe')
|
|
|
|
|
2019-06-28 20:55:05 +00:00
|
|
|
const lodash = require('lodash')
|
|
|
|
|
2019-06-27 20:36:43 +00:00
|
|
|
module.exports = ({ msg }) => {
|
2019-06-28 20:55:05 +00:00
|
|
|
const encoded = {
|
|
|
|
key: encodeURIComponent(msg.key),
|
|
|
|
author: encodeURIComponent(msg.value.author),
|
|
|
|
parent: encodeURIComponent(msg.value.content.root)
|
|
|
|
}
|
|
|
|
|
2019-06-27 20:36:43 +00:00
|
|
|
const url = {
|
2019-06-28 20:55:05 +00:00
|
|
|
author: `/author/${encoded.author}`,
|
|
|
|
likeForm: `/like/${encoded.key}`,
|
|
|
|
context: `/thread/${encoded.key}#${encoded.key}`,
|
|
|
|
parent: `/thread/${encoded.parent}#${encoded.parent}`,
|
2019-06-27 20:36:43 +00:00
|
|
|
avatar: msg.value.meta.author.avatar.url,
|
2019-06-28 20:55:05 +00:00
|
|
|
raw: `/raw/${encoded.key}`
|
2019-06-27 20:36:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const isPrivate = Boolean(msg.value.meta.private)
|
|
|
|
|
|
|
|
const name = msg.value.meta.author.name
|
2019-06-28 20:55:05 +00:00
|
|
|
const timeAgo = msg.value.meta.timestamp.received.since
|
|
|
|
|
|
|
|
const depth = lodash.get(msg, 'value.meta.thread.depth')
|
2019-06-27 20:36:43 +00:00
|
|
|
|
|
|
|
const markdownContent = msg.value.meta.md.block()
|
|
|
|
|
2019-06-28 20:55:05 +00:00
|
|
|
const likeButton = msg.value.meta.voted
|
|
|
|
? { value: 0, class: 'liked' }
|
|
|
|
: { value: 1, class: null }
|
2019-06-27 20:36:43 +00:00
|
|
|
|
|
|
|
const likeCount = msg.value.meta.votes.length
|
|
|
|
|
2019-06-28 20:55:05 +00:00
|
|
|
const parentLink = msg.value.content.root != null
|
|
|
|
? a({ href: url.parent }, 'parent')
|
|
|
|
: null
|
|
|
|
|
2019-06-27 20:36:43 +00:00
|
|
|
const fragment =
|
2019-06-28 20:55:05 +00:00
|
|
|
section({
|
|
|
|
id: msg.key,
|
|
|
|
class: 'message',
|
|
|
|
style: `margin-left: ${depth * 1.5}rem`
|
|
|
|
},
|
2019-06-27 20:36:43 +00:00
|
|
|
header(
|
|
|
|
a({ href: url.author },
|
|
|
|
img({ class: 'avatar', src: url.avatar })
|
|
|
|
),
|
|
|
|
span({ class: 'text' },
|
|
|
|
span({ class: 'author' },
|
|
|
|
a({ href: url.author }, name)
|
|
|
|
),
|
2019-06-28 20:55:05 +00:00
|
|
|
span({ class: 'timestamp' }, ` (${timeAgo})`),
|
2019-06-27 20:36:43 +00:00
|
|
|
isPrivate ? abbr({ title: 'Private' }, '🔒') : null
|
|
|
|
)
|
|
|
|
),
|
|
|
|
article({ class: 'content', innerHTML: markdownContent }),
|
2019-06-29 17:55:43 +00:00
|
|
|
|
|
|
|
// HACK: centered-footer
|
|
|
|
//
|
|
|
|
// Here we create an empty div with an anchor tag that can be linked to.
|
|
|
|
// In our CSS we ensure that this gets centered on the screen when we
|
|
|
|
// link to this anchor tag.
|
|
|
|
//
|
|
|
|
// This is used for redirecting users after they like a post, when we
|
|
|
|
// want the like button that they just clicked to remain close-ish to
|
|
|
|
// where it was before they clicked the button.
|
|
|
|
div({ id: `centered-footer-${encoded.key}`, class: 'centered-footer' }),
|
|
|
|
|
2019-06-27 20:36:43 +00:00
|
|
|
footer(
|
|
|
|
form({ action: url.likeForm, method: 'post' },
|
|
|
|
button({
|
|
|
|
name: 'voteValue',
|
|
|
|
type: 'submit',
|
2019-06-28 20:55:05 +00:00
|
|
|
value: likeButton.value,
|
|
|
|
class: likeButton.class
|
2019-06-27 20:36:43 +00:00
|
|
|
},
|
|
|
|
`❤ ${likeCount}`
|
|
|
|
)
|
|
|
|
),
|
|
|
|
a({ href: url.context }, 'context'),
|
2019-06-28 20:55:05 +00:00
|
|
|
parentLink,
|
2019-06-27 20:36:43 +00:00
|
|
|
a({ href: url.raw }, 'raw')
|
|
|
|
)
|
2019-06-28 20:55:05 +00:00
|
|
|
)
|
2019-06-27 20:36:43 +00:00
|
|
|
|
|
|
|
return fragment
|
|
|
|
}
|