summaryrefslogtreecommitdiff
path: root/demo/components/name.js
blob: ea44f95dc481bf868cec84ed2d850e3f37e02bde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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>`
}