Commit 8b9b3ba8 authored by adamrusly's avatar adamrusly

new: add store

parent 05732c80
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
</q-btn> </q-btn>
<q-btn round flat> <q-btn round flat>
<q-avatar size="26px" @click="loginGoogle"> <q-avatar size="26px" @click="loginGoogle">
<img :src="defaultAvatar"> <img :src="user.avatar">
</q-avatar> </q-avatar>
<q-tooltip>Account</q-tooltip> <q-tooltip>Account</q-tooltip>
</q-btn> </q-btn>
...@@ -137,6 +137,7 @@ ...@@ -137,6 +137,7 @@
</template> </template>
<script> <script>
import { mapGetters,mapActions } from "vuex"
import { fabYoutube } from '@quasar/extras/fontawesome-v5' import { fabYoutube } from '@quasar/extras/fontawesome-v5'
export default { export default {
name: 'MyLayout', name: 'MyLayout',
...@@ -191,7 +192,11 @@ export default { ...@@ -191,7 +192,11 @@ export default {
created () { created () {
this.fabYoutube = fabYoutube this.fabYoutube = fabYoutube
}, },
computed: {
...mapGetters("user", ["user"]),
},
methods: { methods: {
...mapActions('user',['updateUser']),
async loginGoogle() { async loginGoogle() {
try { try {
const googleUser = await this.$gAuth.signIn() const googleUser = await this.$gAuth.signIn()
...@@ -213,6 +218,7 @@ export default { ...@@ -213,6 +218,7 @@ export default {
this.userUpdate.isAuth = true this.userUpdate.isAuth = true
this.defaultAvatar = this.userUpdate.avatar this.defaultAvatar = this.userUpdate.avatar
console.log(bio) console.log(bio)
this.updateUser(this.userUpdate)
// this.upsertUser() // this.upsertUser()
if (this.$route.query.redirect){ if (this.$route.query.redirect){
......
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import user from './store-user'
// import example from './module-example' // import example from './module-example'
Vue.use(Vuex) Vue.use(Vuex)
...@@ -17,7 +17,7 @@ Vue.use(Vuex) ...@@ -17,7 +17,7 @@ Vue.use(Vuex)
export default function (/* { ssrContext } */) { export default function (/* { ssrContext } */) {
const Store = new Vuex.Store({ const Store = new Vuex.Store({
modules: { modules: {
// example user
}, },
// enable strict mode (adds overhead!) // enable strict mode (adds overhead!)
......
const state = {
user: {
token: '',
firstName: '',
lastName: '',
email: '',
avatar: 'https://cdn.quasar.dev/img/boy-avatar.png',
fullname: '',
id: '',
isAdmin: false,
isAuth: false
}
}
const mutations = {
updateUser(state, user) {
Object.assign(state.user, user)
}
}
const actions = {
updateUser({ commit }, payload) {
commit('updateUser',payload)
}
}
const getters = {
user: (state) => {
return state.user
}
}
export default {
namespaced: true,
state,
mutations,
actions,
getters
}
\ No newline at end of file
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