diff --git a/src/components/MyNodes.vue b/src/components/MyNodes.vue index b6e999a65c72e3fc6e54acaa6e21e52276cb8d67..983c9ce8725015f681d91910fae3101cd4fab45c 100644 --- a/src/components/MyNodes.vue +++ b/src/components/MyNodes.vue @@ -53,7 +53,8 @@ export default { watch: { added: function () { - this.loadData() + setTimeout(this.loadData, 500) + }, }, @@ -72,13 +73,21 @@ export default { }, methods: { + emptyData() { + if (this.myNodes.myNodes == 0) { + /// that + } else { + // this + } + }, + loadData() { var nodesFiltered = this.myNodes.myNodes.filter( (nodes) => nodes.node_deleted == false ) this.$store.dispatch('getMynodes') this.myArray = nodesFiltered.reverse() - console.log(this.myArray.length) + // console.log(this.myArray.length) }, editNode(e) { diff --git a/src/components/ToolBar.vue b/src/components/ToolBar.vue index 8957be50ac2ea2b526eb3d6318f414345019daa8..74adceaed7dc4bc8ab2fb0765554dc26925a79e9 100644 --- a/src/components/ToolBar.vue +++ b/src/components/ToolBar.vue @@ -5,6 +5,7 @@ <button>Make Connections</button> <UploadMedia /> <button @click="exitMicrocosm()">Exit</button> + <p>{{ microcosm }}</p> </div> </template> @@ -19,7 +20,13 @@ export default { UploadMedia, }, data() { - return {} + return { + microcosm: 'microcosm name', + } + }, + + mounted() { + this.microcosm = localStorage.getItem('nogg_microcosm') }, mixins: [ diff --git a/src/store/modules/mynodes.js b/src/store/modules/mynodes.js index 66e349272b02ab12a805782fa961040d5d5a5d59..b84eb3c56b187170fecd8ad76e797922fa623c18 100644 --- a/src/store/modules/mynodes.js +++ b/src/store/modules/mynodes.js @@ -54,28 +54,45 @@ export const mutations = { }) }) .catch(function (err) { - // TODO: Does this situation ever hit 404 ? - // console.log(err) + // HITS a 404 on very first node being created if (err.status == 404) { var uniqueid = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) - pouchdb.put({ - _id: deviceName, - nodes: [ - { - node_id: uniqueid, - node_text: '', - node_owner: deviceName, - node_type: 'sheet', - node_shape: 'square', - node_deleted: false, - node_readmode: false, - node_color: '#9bc2d8', - }, - ], - }) + pouchdb + .put({ + _id: deviceName, + nodes: [ + { + node_id: uniqueid, + node_text: '', + node_owner: deviceName, + node_type: 'sheet', + node_shape: 'square', + node_deleted: false, + node_readmode: false, + node_color: '#9bc2d8', + }, + ], + }) + .then(function () { + return pouchdb.get(deviceName).then(function (doc) { + state.myNodes = doc.nodes + var end = Object.keys(state.myNodes).length - 1 + const newNode = { + nodeid: state.myNodes[end].node_id, + nodetext: state.myNodes[end].node_text, + } + // OLD CODE: + // this was to set quick focus on new nodes + // i think... need to check old code + state.activeNode = newNode + }) + }) + .catch(function (err) { + console.log(err) + }) } }) }, diff --git a/src/store/modules/otherNodes.js b/src/store/modules/otherNodes.js index f4c88d9d16726ad6c71d0d76eeb6525df3c79b64..6c4271ea32f1fb6b75f65d1f5d0ed208d8329436 100644 --- a/src/store/modules/otherNodes.js +++ b/src/store/modules/otherNodes.js @@ -15,7 +15,7 @@ export const mutations = { }) .then(function (doc) { state.allNodes = doc.rows - console.log('get all nodes') + }) .catch(function (err) { console.log(err) @@ -23,7 +23,6 @@ export const mutations = { }, SET_OTHER_NODES(state) { - console.log('setting') state.otherNodes = [] var i var j diff --git a/src/views/Collect.vue b/src/views/Collect.vue index 72ccedde46262fe1a32726910fa7c29185f29bc3..ef0360fb1c048a8fcaca2902dce08c46a4a68ae5 100644 --- a/src/views/Collect.vue +++ b/src/views/Collect.vue @@ -11,6 +11,8 @@ import MyNodes from '@/components/MyNodes.vue' export default { mounted() { this.$store.dispatch('getMicrocosm') + // register, i.e. in a `beforeDestroy` hook + window.addEventListener('unload', this.someMethod) }, name: 'Collect', @@ -29,6 +31,14 @@ export default { addedNode() { this.added = !this.added }, + someMethod() { + localStorage.removeItem('nogg_microcosm') + localStorage.removeItem('nogg_name') + + location.assign( + process.env.VUE_APP_HTTP + '://' + process.env.VUE_APP_URL + '/' + ) + }, }, } </script>