Migrated progress bar and progress editor to vuex.

This commit is contained in:
krzysiej
2022-06-14 15:19:21 +02:00
parent 8dbd63478d
commit 5350c5c46b
10 changed files with 131 additions and 56 deletions

View File

@@ -3,7 +3,9 @@ import BookApi from "../../api/book";
const
FETCHING_BOOKS = "FETCHING_BOOKS",
FETCHING_BOOKS_SUCCESS = "FETCHING_BOOKS_SUCCESS",
FETCHING_BOOKS_ERROR = "FETCHING_BOOKS_ERROR";
FETCHING_BOOKS_ERROR = "FETCHING_BOOKS_ERROR",
SETTING_SEARCH_TERM = "SETTING_SEARCH_TERM"
;
export default {
namespaced: true,
@@ -28,9 +30,15 @@ export default {
},
books(state) {
return state.books;
},
isSearching(state) {
return !!state.searchTitle;
}
},
mutations: {
[SETTING_SEARCH_TERM](state, searchTitle) {
state.searchTitle = searchTitle;
},
[FETCHING_BOOKS](state) {
state.isLoading = true;
state.error = null;
@@ -51,8 +59,7 @@ export default {
async findAll({commit, state}, searchTitle) {
commit(FETCHING_BOOKS);
try {
state.searchTitle = searchTitle;
console.info(state.searchTitle);
commit(SETTING_SEARCH_TERM, searchTitle);
let response = await BookApi.booksFetch(state.searchTitle);
commit(FETCHING_BOOKS_SUCCESS, response.data);
return response.data;