diff options
author | Anthony Wang | 2023-02-15 16:22:43 -0500 |
---|---|---|
committer | Anthony Wang | 2023-02-15 16:22:43 -0500 |
commit | 091ff04c2420c8549ff581399212b4e3346864ee (patch) | |
tree | 746ad8767db3f3eab288eab4f08b74c37742777e /components/chat.js | |
parent | fb3c976380e704a1c129f141f0bdb7f5f4576611 (diff) |
Delete all files except for demo
Diffstat (limited to 'components/chat.js')
-rw-r--r-- | components/chat.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/components/chat.js b/components/chat.js new file mode 100644 index 0000000..5095dcd --- /dev/null +++ b/components/chat.js @@ -0,0 +1,65 @@ +import { Name } from './name.js' +import Comments from './comment.js' + +export default { + + components: { Name, Comments }, + + data: ()=> ({ + message: '', + channel: 'demo' + }), + + methods: { + messageObjects(objects) { + return objects.filter(o=> + 'message' in o && + 'timestamp' in o && + typeof o.message == 'string' && + typeof o.timestamp == 'number') + .sortBy('timestamp') + }, + + sendMessage() { + if (!this.message) return + this.$graffitiUpdate({ + message: this.message, + timestamp: Date.now(), + _tags: [this.channel] + }) + this.message = '' + } + }, + + template: ` + <p> + Chat Channel: <input v-model="channel"/> + </p> + + <graffiti-objects :tags="[channel]" v-slot="{objects}"> + <ul v-for="object in messageObjects(objects)"> + <li> + <em><Name :of="object._by"/></em>: + {{ object.message }} + + <Comments :messageID="object._id" /> + + <template v-if="object._by==$graffitiMyID"> + <button @click="object.message+='!!'"> + ‼️ + </button> + + <button @click="delete object._key"> + ❌ + </button> + </template> + </li> + </ul> + </graffiti-objects> + + <form @submit.prevent="sendMessage"> + <input v-model="message"> + <input type="submit" value="Submit"/> + </form>` +} + |