Removed event bus and switched to vuex. Implemented vue dropzone.

This commit is contained in:
krzysiej
2022-06-15 15:19:46 +02:00
parent 5350c5c46b
commit 4536195a4c
16 changed files with 151 additions and 88 deletions

View File

@@ -2,13 +2,15 @@ import Vue from 'vue'
import Vuex from 'vuex'
import booksmodule from './modules/books';
import bookprogressmodule from './modules/bookprogress';
import filemodule from './modules/filemodule';
Vue.use(Vuex)
export default new Vuex.Store({
modules:{
booksmodule,
bookprogressmodule
bookprogressmodule,
filemodule
}
})

View File

@@ -0,0 +1,68 @@
import FileApi from "../../api/file";
import {
REMOVE_FILE_FROM_LIST,
FETCHING_FILES,
FETCHING_FILES_SUCCESS,
FETCHING_FILES_ERROR
} from '../mutation-types.js'
export default {
namespaced: true,
state: {
isLoading: false,
error: null,
files: []
},
getters: {
isLoading(state) {
return state.isLoading;
},
hasError(state) {
return state.error !== null;
},
error(state) {
return state.error;
}
},
mutations: {
[FETCHING_FILES](state) {
state.isLoading = true;
state.error = null;
},
[FETCHING_FILES_SUCCESS](state, files) {
state.isLoading = false;
state.error = null;
state.files = files;
},
[FETCHING_FILES_ERROR](state, error) {
state.isLoading = false;
state.error = error;
state.files = [];
},
[REMOVE_FILE_FROM_LIST](state, fileId) {
const index = state.files.findIndex(file => file.id === fileId);
state.files.splice(index, 1);
}
},
actions: {
async deleteFile({commit}, fileId) {
try {
await FileApi.deleteFile(fileId);
commit(REMOVE_FILE_FROM_LIST, fileId)
} catch (error) {
commit(FETCHING_FILES_ERROR, error);
}
},
async getFiles({commit}, bookId) {
commit(FETCHING_FILES);
try {
let response = await FileApi.getFiles(bookId);
commit(FETCHING_FILES_SUCCESS, response.data);
return response.data;
} catch (error) {
commit(FETCHING_FILES_ERROR, error);
}
},
}
};

View File

@@ -3,5 +3,10 @@ export const
UPDATING_PROGRESS_SUCCESS = "UPDATING_PROGRESS_SUCCESS",
UPDATING_PROGRESS_ERROR = "UPDATING_PROGRESS_ERROR",
TURN_ON_EDIT_MODE = "TURN_ON_EDIT_MODE",
TURN_OFF_EDIT_MODE = "TURN_OFF_EDIT_MODE"
TURN_OFF_EDIT_MODE = "TURN_OFF_EDIT_MODE",
FETCHING_FILES = "FETCHING_FILES",
FETCHING_FILES_SUCCESS = "FETCHING_FILES_SUCCESS",
FETCHING_FILES_ERROR = "FETCHING_FILES_ERROR",
REMOVE_FILE_FROM_LIST = "REMOVE_FILE_FROM_LIST"
;