summaryrefslogtreecommitdiff
path: root/plugins/vue/demo/components/name.js
blob: ec1de622fb26401a602ba3a2f125e431f03ed887 (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
export const Name = {

  props: ["of", "objects"],

  computed: {
    name() {
      const nameObjects = this.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: '{{name}}'
}

export const SetMyName = {

  props: ["tags"],

  data: ()=> ({
    name: ''
  }),

  methods: {
    setMyName() {
      this.$graffitiUpdate({
        name: this.name,
        timestamp: Date.now(),
        of: this.$graffitiID.value,
        _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>`
}