70 lines
1.8 KiB
JavaScript
70 lines
1.8 KiB
JavaScript
import BookApi from "../../api/book";
|
|
import {
|
|
UPDATING_PROGRESS,
|
|
UPDATING_PROGRESS_SUCCESS,
|
|
UPDATING_PROGRESS_ERROR,
|
|
TURN_ON_EDIT_MODE,
|
|
TURN_OFF_EDIT_MODE
|
|
} from '../mutation-types.js'
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
isUpdating: false,
|
|
error: null,
|
|
progress: null,
|
|
editMode: false
|
|
},
|
|
getters: {
|
|
isEditMode(state) {
|
|
return state.editMode;
|
|
},
|
|
isUpdating(state) {
|
|
return state.isUpdating;
|
|
},
|
|
hasError(state) {
|
|
return state.error !== null;
|
|
},
|
|
error(state) {
|
|
return state.error;
|
|
},
|
|
progress(state) {
|
|
return state.progress;
|
|
},
|
|
},
|
|
mutations: {
|
|
[UPDATING_PROGRESS](state) {
|
|
state.isUpdating = true;
|
|
state.error = null;
|
|
state.progress = null;
|
|
},
|
|
[UPDATING_PROGRESS_SUCCESS](state, progress) {
|
|
state.isLoading = false;
|
|
state.error = null;
|
|
state.progress = progress;
|
|
},
|
|
[UPDATING_PROGRESS_ERROR](state, error) {
|
|
state.isLoading = false;
|
|
state.error = error;
|
|
state.progress = null;
|
|
},
|
|
[TURN_ON_EDIT_MODE](state) {
|
|
state.editMode = true;
|
|
},
|
|
[TURN_OFF_EDIT_MODE](state) {
|
|
state.editMode = false;
|
|
}
|
|
},
|
|
actions: {
|
|
async updateProgress({commit}, data) {
|
|
commit(UPDATING_PROGRESS);
|
|
try {
|
|
let response = await BookApi.bookUpdateProgress(data.bookId, data.progress);
|
|
commit(UPDATING_PROGRESS_SUCCESS, response.data.progress);
|
|
return response.data;
|
|
} catch (error) {
|
|
commit(UPDATING_PROGRESS_ERROR, error);
|
|
}
|
|
},
|
|
}
|
|
}; |