feat: Save UI state in the database (#1635)

feat: Save UI state in the database
This commit is contained in:
Pranav Raj S
2021-01-10 19:25:33 +05:30
committed by GitHub
parent 37d8e1c9a0
commit 160a6fc6cf
13 changed files with 129 additions and 15 deletions

View File

@@ -34,6 +34,10 @@ export const getters = {
return _state.currentUser.id;
},
getUISettings(_state) {
return _state.currentUser.ui_settings || {};
},
getCurrentUserAvailabilityStatus(_state) {
return _state.currentUser.availability_status;
},
@@ -95,6 +99,7 @@ export const actions = {
logout({ commit }) {
commit(types.default.CLEAR_USER);
},
updateProfile: async ({ commit }, params) => {
try {
const response = await authAPI.profileUpdate(params);
@@ -105,6 +110,17 @@ export const actions = {
}
},
updateUISettings: async ({ commit }, params) => {
try {
commit(types.default.SET_CURRENT_USER_UI_SETTINGS, params);
const response = await authAPI.updateUISettings(params);
setUser(response.data, getHeaderExpiry(response));
commit(types.default.SET_CURRENT_USER);
} catch (error) {
// Ignore error
}
},
updateAvailability: ({ commit, dispatch }, { availability }) => {
authAPI.updateAvailability({ availability }).then(response => {
const userData = response.data;
@@ -130,7 +146,7 @@ export const actions = {
};
// mutations
const mutations = {
export const mutations = {
[types.default.SET_CURRENT_USER_AVAILABILITY](_state, status) {
Vue.set(_state.currentUser, 'availability_status', status);
},
@@ -145,6 +161,15 @@ const mutations = {
Vue.set(_state, 'currentUser', currentUser);
},
[types.default.SET_CURRENT_USER_UI_SETTINGS](_state, { uiSettings }) {
Vue.set(_state, 'currentUser', {
..._state.currentUser,
ui_settings: {
..._state.currentUser.ui_settings,
...uiSettings,
},
});
},
[types.default.SET_CURRENT_ACCOUNT_ID](_state, accountId) {
Vue.set(_state, 'currentAccountId', Number(accountId));
},