From 23eccb12addefef87d3196ebd5ae791d7c27f258 Mon Sep 17 00:00:00 2001
From: Adam Procter <adamprocter@researchnot.es>
Date: Sat, 11 Sep 2021 14:34:40 +0100
Subject: [PATCH] fixed initialisation of positions document

---
 src/components/MyNodes.vue      |  4 ++++
 src/components/OtherNodes.vue   |  1 +
 src/store/modules/mynodes.js    | 24 ++++++++++++++++++++++--
 src/store/modules/otherNodes.js |  3 ++-
 4 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/components/MyNodes.vue b/src/components/MyNodes.vue
index b30273b..e7bb420 100644
--- a/src/components/MyNodes.vue
+++ b/src/components/MyNodes.vue
@@ -133,11 +133,15 @@ export default {
   },
 
   mounted() {
+    // this.$store.dispatch('getEmoji')
+    // this.$store.dispatch('getPositions')
     setTimeout(this.loadData, 500)
     if (localStorage.nogg_name && localStorage.nogg_microcosm) {
       var devicename = localStorage.nogg_name
       var microcosm = localStorage.nogg_microcosm
       this.$store.dispatch('setMicrocosm', { devicename, microcosm })
+      // this.$store.dispatch('getEmoji')
+      // this.$store.dispatch('getPositions')
     } else {
       console.log('no')
       // go home
diff --git a/src/components/OtherNodes.vue b/src/components/OtherNodes.vue
index 7edaccd..60e529d 100644
--- a/src/components/OtherNodes.vue
+++ b/src/components/OtherNodes.vue
@@ -80,6 +80,7 @@ export default {
 
   mounted() {
     this.$store.dispatch('getOthernodes')
+    this.$store.dispatch('getEmoji')
     setTimeout(this.loadData, 500)
     // this is to get the last letter typed if no space
     // this also loads in new Emoji
diff --git a/src/store/modules/mynodes.js b/src/store/modules/mynodes.js
index d8d86f0..2f7a7a8 100644
--- a/src/store/modules/mynodes.js
+++ b/src/store/modules/mynodes.js
@@ -1,5 +1,6 @@
 var pouchdb
 var deviceName
+
 var docPositions
 
 export const state = {
@@ -63,7 +64,7 @@ export const mutations = {
           })
           return pouchdb
             .put({
-              _id: state.allPos,
+              _id: docPositions,
               _rev: doc._rev,
               positions: doc.positions,
             })
@@ -112,7 +113,26 @@ export const mutations = {
             .catch(function (err) {
               console.log(err)
             })
-          // ADD POSITIONS CODE HERE ONCE WORKING
+          pouchdb.get(docPositions).then(function (doc) {
+            doc.positions.push({
+              node_id: uniqueid,
+              node_x: 0,
+              node_y: 0,
+              node_width: 200,
+              node_height: 370,
+              node_zindex: 0,
+              node_sort: 0,
+            })
+            return pouchdb
+              .put({
+                _id: docPositions,
+                _rev: doc._rev,
+                positions: doc.positions,
+              })
+              .catch(function (err) {
+                console.log(err)
+              })
+          })
         }
       })
   },
diff --git a/src/store/modules/otherNodes.js b/src/store/modules/otherNodes.js
index 249cfa3..0bc76e4 100644
--- a/src/store/modules/otherNodes.js
+++ b/src/store/modules/otherNodes.js
@@ -27,7 +27,8 @@ export const mutations = {
     state.otherNodes = []
     var i
     var j
-    console.log(state.allNodes)
+    // console.log(docEmoji)
+    // console.log(docPositions)
     for (i = 0; i < Object.keys(state.allNodes).length; i++) {
       if (
         state.allNodes[i].id != deviceName &&
-- 
GitLab