Commit fabc4f33 authored by Adam Procter's avatar Adam Procter

store updates

parent e8ebc7f1
Pipeline #197 failed with stages
in 1 minute and 2 seconds
This diff is collapsed.
......@@ -17,6 +17,7 @@ const LOGOUT = "LOGOUT";
export default new Vuex.Store({
state: {
allobjects: [],
registeraccount:[],
database: null,
isLoggedIn: !!localStorage.getItem("token"),
},
......@@ -25,7 +26,15 @@ export default new Vuex.Store({
DB_INIT(state, data) {
state.database = data.database;
},
ADD_KNOWLEDGE_OBJECT (state, payload) {
REGISTER_ACCOUNT(state, data){
state.registeraccount = data.registeraccount;
//state.accounts.push(payload);
if (remote_accounts_db) {
accounts_db.sync(remote_accounts_db)
}
},
SHOW_KNOWLEDGE_OBJECTS (state, payload) {
var ids = [];
state.allobjects.forEach(item => {ids.push(item.id)})
if (!ids.includes(payload.id)){
......@@ -45,10 +54,11 @@ export default new Vuex.Store({
},
actions: {
register() {
register({commit}) {
var uniqueid = Math.random().toString(36).substring(2, 15)
+ Math.random().toString(36).substring(2, 15);
// before : is the couch name to the right is data from component
accounts_db.put({
_id:uniqueid,
name:this.name,
......@@ -57,19 +67,19 @@ export default new Vuex.Store({
permissions:this.permissions,
token:this.token,
verified:this.verified
})
//checkData()
// syncData()
},
syncData(){
if (remote_accounts_db) {
accounts_db.sync(remote_accounts_db)
}
},
checkData(){
// ???
},
})
//this.syncData()
// syncData(){
// if (remote_accounts_db) {
// accounts_db.sync(remote_accounts_db)
// }
// },
// checkData(){
// // ???
// }
commit('REGISTER_ACCOUNT')
},
// https://www.nativescript.org/blog/data-management-with-sqlite-and-vuex-in-a-nativescript-vue-app
// db initialisation, query, and write need to flow through vuex
// db should be stored in store
......@@ -85,8 +95,8 @@ export default new Vuex.Store({
// console.log("OPEN DB ERROR", error);
// });
// },
addKnowledgeObject({ commit }, payload) {
commit('ADD_KNOWLEDGE_OBJECT', payload)
showKnowledgeObjects({ commit }, payload) {
commit('SHOW_KNOWLEDGE_OBJECTS', payload)
},
login({ commit }, payload) {
commit(LOGIN, payload);
......
......@@ -38,7 +38,7 @@ export default {
attachments: true
}).then(result => {
Array.from(result.rows.values()).forEach((element) => {
this.$store.dispatch('addKnowledgeObject', element)
this.$store.dispatch('showKnowledgeObjects', element)
})
})
......
Markdown is supported
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