diff --git a/src/components/MyNodes.vue b/src/components/MyNodes.vue index 429687a0a9fceff7a58491c761a892ad48571772..385e08bb55eb05b915a887dcd08ce47b5468e06b 100644 --- a/src/components/MyNodes.vue +++ b/src/components/MyNodes.vue @@ -1,5 +1,5 @@ <template> - <div v-for="(nodes, index) in myArray" v-bind:key="index"> + <div v-for="(nodes, index) in myArray" :key="index"> <form class="nodes"> <template v-if="nodes.node_readmode == false"> <textarea @@ -55,35 +55,27 @@ export default { }, mounted() { + //console.log('mounted') setTimeout(this.loadData, 500) - //console.log(this.microcosmName.microcosmName) - // NOT SURE THIS IS DOING ANYTHING ??? - // const unwatch = this.$watch('nodesFiltered', (value) => { - // this.$options.myArray = this.nodesFiltered - // this.$forceUpdate() - // // ignore falsy values - // if (!value) return - // // stop watching when nodesFiltered[] is not empty - // if (value && value.length) unwatch() - // // process value here - // }) - }, - watch: { - added: { - deep: true, - handler() { - 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 }) + } else { + console.log('no') + // go home + } }, methods: { loadData() { // console.log('loading data') - this.myArray = this.nodesFiltered - // console.log(this.myArray) - // this.$forceUpdate() + var nodesFiltered = this.myNodes.myNodes.filter( + (nodes) => nodes.node_deleted == false + ) + this.$store.dispatch('getMynodes') + this.myArray = nodesFiltered.reverse() }, editNode(e) { diff --git a/src/components/ToolBar.vue b/src/components/ToolBar.vue index fda9b367d3a6e90aa59a035a56235166993f459b..3e0b432b29bd6a0cf82f5cb3bad0b29c7de24ed2 100644 --- a/src/components/ToolBar.vue +++ b/src/components/ToolBar.vue @@ -4,6 +4,7 @@ <button>Select Node</button> <button>Make Connections</button> <UploadMedia /> + <button @click="exitMicrocosm()">Exit</button> </div> </template> @@ -37,6 +38,15 @@ export default { this.$emit('added-node') this.$store.dispatch('addNode') }, + exitMicrocosm() { + + localStorage.removeItem('nogg_microcosm') + localStorage.removeItem('nogg_name') + + location.assign( + process.env.VUE_APP_HTTP + '://' + process.env.VUE_APP_URL + '/' + ) + }, }, } </script> diff --git a/src/store/modules/mynodes.js b/src/store/modules/mynodes.js index 5ae758bf3856b76af0285dff799438c775e9e4bb..9997cfef1a38e132f4282141763ad47bdc6c01bd 100644 --- a/src/store/modules/mynodes.js +++ b/src/store/modules/mynodes.js @@ -6,8 +6,6 @@ var deviceName export const state = { myNodes: [], activeNode: {}, - lastMicrocosm: '', - lastdeviceName: '', } export const mutations = { @@ -81,7 +79,7 @@ export const mutations = { }) }, GET_MY_NODES() { - // console.log('called ' + deviceName) + console.log('called ' + deviceName) pouchdb .get(deviceName) .then(function (doc) { @@ -108,7 +106,6 @@ export const mutations = { .get(deviceName) .then(function (doc) { // put the store into pouchdb - return pouchdb.bulkDocs([ { _id: deviceName, diff --git a/src/store/modules/setup.js b/src/store/modules/setup.js index c934ada258fc63a194e37c12ae1e715d6b072bc4..065fedff1f8fba2c438bbfad705f44eff295186c 100644 --- a/src/store/modules/setup.js +++ b/src/store/modules/setup.js @@ -14,9 +14,6 @@ export const mutations = { SET_MICROCOSM(state, e) { state.deviceName = e.devicename state.microcosmName = e.microcosm - // if (state.microcosmName == '') { - // console.log('empty') - // } pouchdb = new PouchDB(state.microcosmName) state.pouchdb = pouchdb diff --git a/src/views/Collect.vue b/src/views/Collect.vue index 98d210c1b839f936223efc9d40af094dfffe344b..a0717290744443694c47788f57985acd34e8d6ae 100644 --- a/src/views/Collect.vue +++ b/src/views/Collect.vue @@ -1,6 +1,6 @@ <template> <ToolBar @added-node="addedNode" /> - <MyNodes :added="added" /> + <MyNodes :added="added" :key="componentKey" /> </template> <script> @@ -21,6 +21,7 @@ export default { data() { return { + componentKey: 0, added: true, } }, @@ -29,6 +30,11 @@ export default { addedNode() { //console.log('I hear you!') this.added = !this.added + this.forceRender() + }, + forceRender() { + // reloads the data after adding a node + this.componentKey += 1 }, }, }