-
Notifications
You must be signed in to change notification settings - Fork 38
/
retort-toggle.js.es6
32 lines (26 loc) · 972 Bytes
/
retort-toggle.js.es6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { h } from 'virtual-dom'
import { emojiUrlFor } from 'discourse/lib/text'
export default Ember.Object.create({
render(widget) {
this.state = widget.state
return [this.emoji(), this.count(), this.tooltip()]
},
emoji() {
return h('img.emoji', { src: emojiUrlFor(this.state.emoji), alt: `:${this.state.emoji}:` })
},
count() {
if (this.state.usernames.length < 2) { return }
return h('span.post-retort__count', this.state.usernames.length.toString())
},
tooltip() {
return h('span.post-retort__tooltip', this.sentence())
},
sentence() {
let usernames = this.state.usernames
switch(usernames.length) {
case 1: return `${usernames[0]} reacted with :${this.state.emoji}:`
case 2: return `${usernames[0]} and ${usernames[1]} reacted with :${this.state.emoji}:`
default: return `${usernames[0]}, ${usernames[1]}, and ${usernames.length - 2} others reacted with :${this.state.emoji}:`
}
}
})