summaryrefslogtreecommitdiff
path: root/components/name.js
diff options
context:
space:
mode:
Diffstat (limited to 'components/name.js')
-rw-r--r--components/name.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/components/name.js b/components/name.js
new file mode 100644
index 0000000..ea44f95
--- /dev/null
+++ b/components/name.js
@@ -0,0 +1,56 @@
+export const Name = {
+
+ props: ["of"],
+
+ methods: {
+ name(objects) {
+ const nameObjects = objects
+ .filter(o=>
+ 'name' in o &&
+ 'of' in o &&
+ 'timestamp' in o &&
+ typeof o.name == 'string' &&
+ o.of == this.of &&
+ o._by == this.of &&
+ typeof o.timestamp == 'number')
+ .sortBy('-timestamp')
+
+ return nameObjects.length?
+ nameObjects[0].name : 'anonymous'
+ }
+ },
+
+ template: `
+ <graffiti-objects :tags="[of]" v-slot="{objects}">
+ {{ name(objects) }}
+ </graffiti-objects>`
+}
+
+export const SetMyName = {
+
+ props: ["tags"],
+
+ data: ()=> ({
+ name: ''
+ }),
+
+ methods: {
+ setMyName() {
+ this.$graffitiUpdate({
+ name: this.name,
+ timestamp: Date.now(),
+ of: this.$graffitiMyID,
+ _tags: this.tags
+ })
+ this.name = ''
+ }
+ },
+
+ template: `
+ <form @submit.prevent="setMyName">
+ <label for="nameBox">Change your name:</label>
+ <input v-model="name" id="nameBox"/>
+ <br>
+ <input type="submit" value="Submit"/>
+ </form>`
+}