Commit 939cdc7f authored by Adam Procter's avatar Adam Procter
Browse files

update to my vuex store

parent 31991a98
VUE_APP_COUCH_HTTP=http
VUE_APP_COUCH_USER=auto-admin
VUE_APP_COUCH_PASS=testing@
VUE_APP_COUCH_URL=127.0.0.1:5984/
\ No newline at end of file
......@@ -8,7 +8,8 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.9.1",
"core-js": "^3.10.0",
"pouchdb": "^7.2.2",
"vue": "^3.0.9",
"vue-router": "^4.0.5",
"vuex": "^4.0.0-0"
......
......@@ -51,7 +51,7 @@
export default {
name: 'JoinMicrocosm',
data: function() {
data: function () {
return {
// what you are calling yourself / device
name: '',
......@@ -60,7 +60,7 @@ export default {
// Next dataset related to microcosm
microcosm: '',
microcosmSet: false,
microcosmFormatted: ''
microcosmFormatted: '',
}
},
......@@ -86,13 +86,13 @@ export default {
this.microcosmSet = true
localStorage.setItem('nogg_microcosm', this.microcosmFormatted)
// now we sent this same data set to the store
// this.$store.dispatch('setMicrocosm', this.microcosmFormatted),
this.$store.dispatch('setMicrocosm', this.microcosmFormatted)
},
focusInput() {
this.$refs.microcosm.focus()
}
}
},
},
}
</script>
......
import { createStore } from 'vuex'
import PouchDB from 'pouchdb'
import Router from '@/router'
export default createStore({
state: {},
mutations: {},
actions: {},
// Checking for previous microcosm last entered from LocalStorage
if (localStorage.getItem('nogg_microcosm') == null) {
var microcosm = 'first_visit'
} else {
microcosm = localStorage.getItem('nogg_microcosm')
}
// Checking for previous name last entered from LocalStorage
if (localStorage.getItem('nogg_name') == null) {
var name = 'no_name'
} else {
name = localStorage.getItem('nogg_name')
}
// set up PouchDB and add a remote from env files
var pouchdb = new PouchDB(microcosm)
var remote =
process.env.VUE_APP_COUCH_HTTP +
'://' +
process.env.VUE_APP_COUCH_USER +
':' +
process.env.VUE_APP_COUCH_PASS +
process.env.VUE_APP_COUCH_URL +
microcosm +
'/'
export const store = createStore({
state() {
return {
version: process.env.VUE_APP_VERSION,
microcosm: '',
name: name,
configRemote: [],
}
},
mutations: {
SET_NAME(state, doc) {
state.name = doc
store.commit('GET_MY_NODES')
},
SET_MICROCOSM(state, doc) {
const urlmicrocosm = Router.currentRoute.params.microcosm
pouchdb.close().then(function () {
// if the URL Parameter has /microcosm/usethisname
if (urlmicrocosm != undefined) {
microcosm = urlmicrocosm
localStorage.setItem('nogg_microcosm', microcosm)
} else {
microcosm = doc
}
if (state.configRemote && state.configRemote.length > 0) {
remote =
state.configRemote[0].protocol +
state.configRemote[0].couchusername +
':' +
state.configRemote[0].couchpassword +
'@' +
state.configRemote[0].couchurl +
'/' +
microcosm +
'/'
} else {
remote =
process.env.VUE_APP_COUCH_HTTP +
'://' +
process.env.VUE_APP_COUCH_USER +
':' +
process.env.VUE_APP_COUCH_PASS +
process.env.VUE_APP_COUCH_URL +
microcosm +
'/'
}
store.dispatch('syncDB')
})
},
},
actions: {
syncDB: () => {
pouchdb.replicate.from(remote).on('complete', function () {
// turn on two-way, continuous, retriable sync
pouchdb
.sync(remote, {
live: true,
since: 'now',
retry: true,
attachments: true,
})
.on('change', function () {
// pop info into function to find out more
})
.on('paused', function () {})
.on('active', function () {})
.on('denied', function () {})
.on('complete', function () {})
.on('error', function (err) {
console.log(err)
})
})
},
setName: ({ commit }, e) => {
commit('SET_NAME', e)
},
setMicrocosm: ({ commit }, e) => {
commit('SET_MICROCOSM', e)
},
},
modules: {},
})
store.dispatch('syncDB')
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment