diff --git a/src/components/OtherNodes.vue b/src/components/OtherNodes.vue index 413c18b6207cce214ba2ff7b3d01ace1dd5ac8d7..b617d93d2e1019b0ec327ecc427e6fb97487b08b 100644 --- a/src/components/OtherNodes.vue +++ b/src/components/OtherNodes.vue @@ -1,10 +1,8 @@ <template> - <div v-for="(nodes, index) in otherArray" :key="index"> - <p - class="readmode" - :id="nodes.node_id" - :inner-html.prop="nodes.node_text" - ></p> + <div v-for="(nodes, index) in otherNodes.otherNodes" :key="index"> + <p class="readmode" :id="nodes.id"> + {{ nodes.text }} + </p> </div> </template> @@ -17,45 +15,20 @@ import { mapState } from 'vuex' export default { name: 'OtherNodes', - data() { - return { - otherArray: [], - } - }, - computed: { ...mapState({ otherNodes: (state) => state.otherNodes, }), }, - // watch: { - // added: function () { - // this.loadData() - // }, - // }, - mounted() { - //console.log('mounted') + this.$store.dispatch('getOthernodes') setTimeout(this.loadData, 500) - - // if (localStorage.nogg_microcosm) { - // // var devicename = localStorage.nogg_name - // var microcosm = localStorage.nogg_microcosm - // this.$store.dispatch('setMicrocosm', { microcosm }) - // } else { - // console.log('no') - // // go home - // } }, methods: { loadData() { - var othersFiltered = this.otherNodes.otherNodes.filter( - (nodes) => nodes.node_deleted == false - ) - this.$store.dispatch('getOthernodes') - this.otherArray = othersFiltered + this.$store.dispatch('setOthernodes') }, }, } diff --git a/src/store/modules/otherNodes.js b/src/store/modules/otherNodes.js index 79539cf00b61b60abb11573c859eb4c148a1db53..f4c88d9d16726ad6c71d0d76eeb6525df3c79b64 100644 --- a/src/store/modules/otherNodes.js +++ b/src/store/modules/otherNodes.js @@ -1,7 +1,5 @@ var pouchdb - -// PRETTY SURE this is wrong -import * as store from '@/store/store.js' +var deviceName export const state = { allNodes: [], @@ -17,8 +15,7 @@ export const mutations = { }) .then(function (doc) { state.allNodes = doc.rows - // TODO: THIS IS NOT working - store.commit('SET_OTHER_NODES') + console.log('get all nodes') }) .catch(function (err) { console.log(err) @@ -26,19 +23,22 @@ export const mutations = { }, SET_OTHER_NODES(state) { + console.log('setting') state.otherNodes = [] var i var j for (i = 0; i < Object.keys(state.allNodes).length; i++) { - for (j = 0; j < Object.keys(state.allNodes[i].doc.nodes).length; j++) { - const newNode = { - id: state.allNodes[i].doc.nodes[j].node_id, - text: state.allNodes[i].doc.nodes[j].node_text, - deleted: state.allNodes[i].doc.nodes[j].node_deleted, - color: state.allNodes[i].doc.nodes[j].node_color, + if (state.allNodes[i].id != deviceName) { + for (j = 0; j < Object.keys(state.allNodes[i].doc.nodes).length; j++) { + const newNode = { + id: state.allNodes[i].doc.nodes[j].node_id, + text: state.allNodes[i].doc.nodes[j].node_text, + deleted: state.allNodes[i].doc.nodes[j].node_deleted, + color: state.allNodes[i].doc.nodes[j].node_color, + } + state.otherNodes.push(newNode) } - state.otherNodes.push(newNode) } } }, @@ -47,9 +47,15 @@ export const mutations = { export const actions = { getOthernodes: ({ commit }) => { commit('GET_ALL_NODES') + commit('SET_OTHER_NODES') + }, + + setOthernodes: ({ commit }) => { + commit('SET_OTHER_NODES') }, getMicrocosm(vuexContext) { + deviceName = vuexContext.rootState.setup.deviceName pouchdb = vuexContext.rootState.setup.pouchdb }, } diff --git a/src/store/modules/setup.js b/src/store/modules/setup.js index 065fedff1f8fba2c438bbfad705f44eff295186c..bc8b33ff44f3c7fb5064bf150e946ea67ee32316 100644 --- a/src/store/modules/setup.js +++ b/src/store/modules/setup.js @@ -79,8 +79,7 @@ export const actions = { retry: true, }) .on('change', function () { - // console.log('change happened') - // vuexContext.dispatch('getNodes', null, { root: true }) + vuexContext.dispatch('getOthernodes', null, { root: true }) }) .on('paused', function () {}) .on('active', function () { diff --git a/src/views/Cards.vue b/src/views/Cards.vue index 29a8532c47084fd570d29156fc6ccbdee3e7215b..9510b7f8c467c5ca869ce33b520fef6f3acb97fa 100644 --- a/src/views/Cards.vue +++ b/src/views/Cards.vue @@ -1,7 +1,7 @@ <template> <ToolBar @added-node="addedNode" /> - <MyNodes :added="added" /> <OtherNodes /> + <MyNodes :added="added" /> </template> <script>