MyNodes.vue 4 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
      <template v-if="nodes.node_readmode == false">
5
6
7
        <textarea
          v-model="nodes.node_text"
          @input="editNode"
8
          :id="nodes.node_id"
9
10
11
12
13
          ref="textentry"
          placeholder="Type your thoughts and ideas here! (auto saved every keystroke)"
          rows="5"
        ></textarea>
        <p class="info">*markdown supported &amp; autosaves</p>
Adam Procter's avatar
Adam Procter committed
14
15
16
17
18

        <VSwatches
          v-model="nodes.node_color"
          :swatches="swatches"
          :shapes="shapes"
Adam Procter's avatar
Adam Procter committed
19
          @update:modelValue="chooseColor(nodes.node_id, nodes.node_color)"
Adam Procter's avatar
Adam Procter committed
20
21
22
23
24
25
26
27
          show-border
          show-fallback
          fallback-input-type="color"
        >
          <template v-slot:trigger>
            <button @click.prevent>{{ nodes.node_color }}</button>
          </template>
        </VSwatches>
28
29
30
31
32
33
34
35
36
        <select
          v-model="nodes.node_shape"
          @input="setShape"
          :id="nodes.node_id"
        >
          <option value="square">Square</option>
          <option value="circle">Circle</option>
          <option value="triangle">Triangle</option>
          <option value="hexegon">Hexegon</option>
Adam Procter's avatar
Adam Procter committed
37
38
        </select>

39
40
41
42
43
44
45
        <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>
46
47
48
49
50
51
52
    </form>
  </div>
</template>

<script>
// @ is an alias to /src
import { mapState } from 'vuex'
Adam Procter's avatar
Adam Procter committed
53
import VSwatches from 'vue3-swatches'
Adam Procter's avatar
Adam Procter committed
54
// import marked from 'marked'
55
56

export default {
57
  name: 'MyNodes',
58

Adam Procter's avatar
Adam Procter committed
59
60
  components: { VSwatches },

61
62
63
64
65
66
67
  props: {
    added: Boolean,
  },

  data() {
    return {
      myArray: [],
Adam Procter's avatar
Adam Procter committed
68
69
70
71
72
73
74
75
      shapes: 'circles',
      // swatches: [{ color: '#F493A7', showBorder: true }],
      swatches: [
        ['#EB5757', '#F2994A', '#F2C94C'],
        ['#219653', '#27AE60', '#6FCF97'],
        ['#2F80ED', '#2D9CDB', '#56CCF2'],
        ['#9B51E0', '#BB6BD9', '#E9B7FC'],
      ],
76
77
78
79
80
    }
  },

  computed: {
    ...mapState({
81
      myNodes: (state) => state.myNodes,
82
83
84
    }),
  },

Adam Procter's avatar
Adam Procter committed
85
86
  watch: {
    added: function () {
87
      setTimeout(this.loadData, 500)
Adam Procter's avatar
Adam Procter committed
88
89
90
    },
  },

91
92
  mounted() {
    setTimeout(this.loadData, 500)
Adam Procter's avatar
Adam Procter committed
93
94
95
96
97
98
99
100
    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
    }
101
102
103
104
  },

  methods: {
    loadData() {
Adam Procter's avatar
Adam Procter committed
105
106
107
108
109
      var nodesFiltered = this.myNodes.myNodes.filter(
        (nodes) => nodes.node_deleted == false
      )
      this.$store.dispatch('getMynodes')
      this.myArray = nodesFiltered.reverse()
110
111
112
113
114
115
116
    },

    editNode(e) {
      var nodeid = e.target.id
      var nodetext = e.target.value
      this.$store.dispatch('editNode', { nodeid, nodetext })
    },
117
118
119
120
121
122
123
124
125
126
127
128
129
130

    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)
    },
Adam Procter's avatar
Adam Procter committed
131
132

    chooseColor(nodeid, color) {
133
134
135
136
137
138
139
140
141
142
      this.$store.dispatch('colorNode', { nodeid, color })
      setTimeout(this.loadData, 500)
    },

    setShape(e) {
      var nodeid = e.target.id
      var shape = e.target.value

      this.$store.dispatch('setShape', { nodeid, shape })
      setTimeout(this.loadData, 500)
Adam Procter's avatar
Adam Procter committed
143
    },
144
145
146
147
148
149
150
151
152
153
154
155
  },
}
</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
156
157

textarea {
Adam Procter's avatar
Adam Procter committed
158
159
160
161
162
163
  font-size: 1em;
  resize: none;
  border: none;
  background-color: rgb(187, 225, 247);
  width: 100%;
  box-sizing: border-box;
ap2x07's avatar
ap2x07 committed
164
}
165
</style>