summaryrefslogtreecommitdiff
path: root/demo/components/like-button.js
diff options
context:
space:
mode:
Diffstat (limited to 'demo/components/like-button.js')
-rw-r--r--demo/components/like-button.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/demo/components/like-button.js b/demo/components/like-button.js
new file mode 100644
index 0000000..1c9649a
--- /dev/null
+++ b/demo/components/like-button.js
@@ -0,0 +1,36 @@
+export default {
+
+ props: ['messageID'],
+
+ methods: {
+ likeObjects(objects) {
+ return objects.filter(o=>
+ 'like' in o &&
+ 'timestamp' in o &&
+ o.like == this.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]
+ })
+ }
+ }
+ },
+
+ 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>`
+}
+