MyNodes.vue 2.64 KB
Newer Older
1
<template>
Adam Procter's avatar
Adam Procter committed
2
  <div v-for="(nodes, index) in myArray" :key="index">
3
    <form class="nodes">
4
5
6
7
      <template v-if="nodes.read_mode == false">
        <textarea
          v-model="nodes.node_text"
          @input="editNode"
8
          :id="nodes.node_id"
9
10
11
12
13
14
15
16
17
18
19
20
21
22
          ref="textentry"
          placeholder="Type your thoughts and ideas here! (auto saved every keystroke)"
          rows="5"
        ></textarea>
        <p class="info">*markdown supported &amp; autosaves</p>
        <button>Colour</button>
        <button>Shape</button>
        <button @click.prevent="toggleMode(nodes.node_id)">Read</button>
        <button @click.prevent="discardNode(nodes.node_id)">Discard</button>
      </template>
      <template v-else>
        <p class="readmode" :id="nodes.node_id">{{ nodes.node_text }}</p>
        <button @click.prevent="toggleMode(nodes.node_id)">Edit</button>
      </template>
23
24
25
26
27
28
29
    </form>
  </div>
</template>

<script>
// @ is an alias to /src
import { mapState } from 'vuex'
Adam Procter's avatar
Adam Procter committed
30

Adam Procter's avatar
Adam Procter committed
31
// import marked from 'marked'
32
33

export default {
34
  name: 'MyNodes',
35
36
37
38
39
40
41
42
43
44
45
46
47

  props: {
    added: Boolean,
  },

  data() {
    return {
      myArray: [],
    }
  },

  computed: {
    ...mapState({
48
      myNodes: (state) => state.myNodes,
49
50
51
    }),
  },

Adam Procter's avatar
Adam Procter committed
52
53
  watch: {
    added: function () {
54
      setTimeout(this.loadData, 500)
Adam Procter's avatar
Adam Procter committed
55
56
57
    },
  },

58
59
  mounted() {
    setTimeout(this.loadData, 500)
Adam Procter's avatar
Adam Procter committed
60
61
62
63
64
65
66
67
    if (localStorage.nogg_name && localStorage.nogg_microcosm) {
      var devicename = localStorage.nogg_name
      var microcosm = localStorage.nogg_microcosm
      this.$store.dispatch('setMicrocosm', { devicename, microcosm })
    } else {
      console.log('no')
      // go home
    }
68
69
70
71
  },

  methods: {
    loadData() {
Adam Procter's avatar
Adam Procter committed
72
73
74
75
76
      var nodesFiltered = this.myNodes.myNodes.filter(
        (nodes) => nodes.node_deleted == false
      )
      this.$store.dispatch('getMynodes')
      this.myArray = nodesFiltered.reverse()
77
78
79
80
81
82
83
    },

    editNode(e) {
      var nodeid = e.target.id
      var nodetext = e.target.value
      this.$store.dispatch('editNode', { nodeid, nodetext })
    },
84
85
86
87
88
89
90
91
92
93
94
95
96
97

    discardNode(e) {
      if (confirm('Confirm discard?')) {
        this.$store.dispatch('discardNode', { e })
        setTimeout(this.loadData, 500)
      } else {
        // nothing happens
      }
    },

    toggleMode(e) {
      this.$store.dispatch('toggleMode', { e })
      setTimeout(this.loadData, 500)
    },
98
99
100
101
102
103
104
105
106
107
108
109
  },
}
</script>

<style scoped>
.nodes {
  width: 95%;
  border: 2px dashed black;
  background-color: rgb(155, 194, 216);
  margin-top: 1em;
  margin-left: 0.5em;
}
ap2x07's avatar
ap2x07 committed
110
111

textarea {
Adam Procter's avatar
Adam Procter committed
112
113
114
115
116
117
  font-size: 1em;
  resize: none;
  border: none;
  background-color: rgb(187, 225, 247);
  width: 100%;
  box-sizing: border-box;
ap2x07's avatar
ap2x07 committed
118
}
119
</style>