summaryrefslogtreecommitdiff
path: root/components/like-button.js
diff options
context:
space:
mode:
authorAnthony Wang2023-02-15 16:22:43 -0500
committerAnthony Wang2023-02-15 16:22:43 -0500
commit091ff04c2420c8549ff581399212b4e3346864ee (patch)
tree746ad8767db3f3eab288eab4f08b74c37742777e /components/like-button.js
parentfb3c976380e704a1c129f141f0bdb7f5f4576611 (diff)
Delete all files except for demo
Diffstat (limited to 'components/like-button.js')
-rw-r--r--components/like-button.js36
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>`
+}
+