From 026c457b6aeb8def8740854ce348766ab7b0529f Mon Sep 17 00:00:00 2001 From: Adam Procter <adamprocter@researchnot.es> Date: Tue, 31 Aug 2021 14:16:28 +0100 Subject: [PATCH] fixed initial node creation to work as expected --- src/components/MyNodes.vue | 13 +++++++-- src/components/ToolBar.vue | 9 +++++- src/store/modules/mynodes.js | 51 ++++++++++++++++++++++----------- src/store/modules/otherNodes.js | 3 +- src/views/Collect.vue | 10 +++++++ 5 files changed, 64 insertions(+), 22 deletions(-) diff --git a/src/components/MyNodes.vue b/src/components/MyNodes.vue index b6e999a..983c9ce 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 8957be5..74adcea 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 66e3492..b84eb3c 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 f4c88d9..6c4271e 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 72ccedd..ef0360f 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> -- GitLab