diff options
Diffstat (limited to 'components/like-button.js')
-rw-r--r-- | components/like-button.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/components/like-button.js b/components/like-button.js new file mode 100644 index 0000000..6f65ac6 --- /dev/null +++ b/components/like-button.js @@ -0,0 +1,36 @@ +export default { + + props: ['messageID', 'parent'], + + methods: { + likeObjects(objects, messageID=this.messageID) { + return objects.filter(o=> + 'like' in o && + 'timestamp' in o && + o.like == messageID && + typeof o.timestamp == 'number') + + }, + + toggleLike(objects) { + const myLikes = this.likeObjects(objects).mine + if (myLikes.length) { + myLikes.removeMine() + } else { + this.$graffitiUpdate({ + like: this.messageID, + timestamp: Date.now(), + _tags: [this.messageID, this.parent] + }) + } + } + }, + + template: ` + <graffiti-objects :tags="[messageID]" v-slot="{objects}"> + <button @click="toggleLike(objects)" :class="likeObjects(objects).mine.length?'button-primary':''"> + 👍 {{ likeObjects(objects).length }} + </button> + </graffiti-objects>` +} + |