Blame view
src/store/store.js
3.35 KB
03dcbf0c1
|
1 2 3 4 5 6 7 |
import Vue from 'vue' import Vuex from 'vuex' import createPersistedState from 'vuex-persistedstate' Vue.use(Vuex) export default new Vuex.Store({ |
37150e7c1
|
8 9 10 |
strict: true, plugins: [ createPersistedState() |
03dcbf0c1
|
11 12 13 14 15 |
], state: { token: null, data: null, isUserLoggedIn: false, |
e3e2a04c6
|
16 |
id: null, |
99cd79184
|
17 |
role: null, |
68d742034
|
18 19 |
// schoolId: null, schoolToken: null, |
32fcd6960
|
20 21 |
schoolRole: null, studentsData: [], |
898c80f27
|
22 |
activeStudent: {}, |
32fcd6960
|
23 24 25 26 27 |
}, getters: { GET_STUDENTS_DATA: state => { return state.studentsData }, |
898c80f27
|
28 29 30 |
GET_ACTIVE_STUDENT: state => { return state.activeStudent }, |
612b79bb4
|
31 32 33 |
GET_TOKEN: state => { return state.token }, |
32fcd6960
|
34 |
|
03dcbf0c1
|
35 36 37 |
}, // serve as the one and only way to change the state of the data in the state object mutations: { |
1efb20890
|
38 39 40 41 |
RESET_STORE(state, defaultState) { state = defaultState // state.isUserLoggedIn = false }, |
37150e7c1
|
42 |
setToken(state, token) { |
03dcbf0c1
|
43 |
state.token = token |
32fcd6960
|
44 |
//state.isUserLoggedIn = !!(token) |
37150e7c1
|
45 46 47 48 |
if (token != null) { state.isUserLoggedIn = true } else { state.isUserLoggedIn = false |
ac6f8f44b
|
49 |
state.isSchoolLoggedIn = false |
37150e7c1
|
50 |
} |
03dcbf0c1
|
51 |
}, |
68d742034
|
52 53 |
setSchoolToken(state, schoolToken) { state.schoolToken = schoolToken |
32fcd6960
|
54 |
//state.isUserLoggedIn = !!(token) |
68d742034
|
55 56 57 58 59 60 |
if (schoolToken != null) { state.isSchoolLoggedIn = true } else { state.isSchoolLoggedIn = false } }, |
37150e7c1
|
61 |
setUser(state, data) { |
03dcbf0c1
|
62 63 |
state.data = data }, |
37150e7c1
|
64 65 |
Id(state, id) { state.id = id |
03dcbf0c1
|
66 |
}, |
37150e7c1
|
67 68 |
Role(state, role) { state.role = role |
99cd79184
|
69 |
}, |
68d742034
|
70 71 72 |
setSchoolRole(state, schoolRole) { state.schoolRole = schoolRole }, |
32fcd6960
|
73 74 75 |
SET_STUDENTS_DATA(state, data) { state.studentsData = data }, |
898c80f27
|
76 77 78 |
SET_ACTIVE_STUDENT(state, data) { state.activeStudent = data }, |
68d742034
|
79 80 81 |
// SchoolId(state, schoolId) { // state.schoolId = schoolId // } |
37150e7c1
|
82 |
}, |
03dcbf0c1
|
83 84 |
//Action methods are referred to as being "dispatched" actions: { |
1efb20890
|
85 86 87 88 89 |
RESET_STORE({ commit }, defaultState) { commit('RESET_STORE', defaultState) }, |
32fcd6960
|
90 91 92 |
setToken({ commit }, token) { |
03dcbf0c1
|
93 94 |
commit('setToken', token) }, |
32fcd6960
|
95 96 97 |
setSchoolToken({ commit }, schoolToken) { |
68d742034
|
98 99 |
commit('setSchoolToken', schoolToken) }, |
32fcd6960
|
100 101 102 |
setUser({ commit }, data) { |
03dcbf0c1
|
103 104 |
commit('setUser', data) }, |
32fcd6960
|
105 106 107 108 109 |
SET_STUDENTS_DATA({ commit }, data) { commit('SET_STUDENTS_DATA', data) }, |
898c80f27
|
110 111 112 113 114 |
SET_ACTIVE_STUDENT({ commit }, data) { commit('SET_ACTIVE_STUDENT', data) }, |
32fcd6960
|
115 116 117 |
Id({ commit }, id) { |
e3e2a04c6
|
118 |
commit('Id', id) |
37150e7c1
|
119 |
}, |
32fcd6960
|
120 121 122 |
Role({ commit }, role) { |
37150e7c1
|
123 |
commit('Role', role) |
99cd79184
|
124 |
}, |
32fcd6960
|
125 126 127 |
setSchoolRole({ commit }, schoolRole) { |
68d742034
|
128 129 130 131 132 |
commit('setSchoolRole', schoolRole) }, // SchoolId({ commit }, schoolId) { // commit('SchoolId', schoolId) // } |
03dcbf0c1
|
133 134 |
} |
37150e7c1
|
135 |
|
03dcbf0c1
|
136 |
}) |