diff --git a/src/App.vue b/src/App.vue index 479d493..60e5d0d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,130 +1,132 @@ diff --git a/src/components/Error.vue b/src/components/Error.vue index dff50e9..82756cf 100644 --- a/src/components/Error.vue +++ b/src/components/Error.vue @@ -1,25 +1,38 @@ - - diff --git a/src/components/ui/WTLSnackbar.vue b/src/components/ui/WTLSnackbar.vue new file mode 100644 index 0000000..a5d6f80 --- /dev/null +++ b/src/components/ui/WTLSnackbar.vue @@ -0,0 +1,83 @@ + + + + + diff --git a/src/store/actions.js b/src/store/actions.js index 08a8129..175c5f5 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -1,106 +1,111 @@ import { Categories } from "api/Categories" import { Courses } from "api/Courses" import { Pages } from "api/Pages" import { Chapters } from "api/Chapters" import { Polling } from "api/Polling" import { Api } from "api/Api" export const actions = { FETCH_HOME({ commit }) { return Api.get("") .then((response) => { commit("SET_NAVIGATION_LINKS", { navigationLinks: response._links }) }) }, FETCH_ROOT_CATEGORIES({ commit }) { return Categories.getRootCategories() .then((response) => { commit("SET_ROOT_CATEGORIES", { categories: response.data }) }) }, FETCH_CATEGORY({ commit }, { categoryName }) { return Categories.get(categoryName) .then((response) => { commit("SET_CATEGORY", { category: response.data }) }) }, FETCH_COURSE({ commit }, { courseName }) { return Courses.get(courseName) .then((response) => { const resp = Object.assign({}, response) commit("SET_COURSE", { course: resp }) for (const chapter of resp.chapters) { commit("SET_CHAPTER", { chapter: chapter }) } return response }).then((response) => { commit("SET_NAVIGATION_LINKS", { navigationLinks: response._links }) }) }, FETCH_COURSES({ commit }, { page }) { return Courses.getAll(page) .then((response) => { const resp = Object.assign({}, response) commit("CLEAR_COURSES") for (const course of resp._items) { commit("SET_COURSE", { course: course }) } return response }).then((response) => { commit("SET_NAVIGATION_LINKS", { navigationLinks: response._links }) return response }).then((response) => { commit("SET_META", { meta: response._meta }) }) }, FETCH_PAGE({ commit }, { pageTitle }) { return Pages.get(pageTitle) .then((response) => { commit("SET_PAGE", { page: response }) }) }, FETCH_CHAPTER({ commit }, { chapterName }) { return Chapters.get(chapterName) .then((response) => { const resp = Object.assign({}, response) commit("SET_CHAPTER", { page: resp }) for (const page of resp.pages) { commit("SET_PAGE", { page: page }) } }) }, START_POLLING({ commit }) { return Polling.start() .then((response) => { const pollingId = response.data.pollingId const pollTimer = setInterval(() => { Polling.getStatus(pollingId) .then((response) => { commit("UPDATE_POLLING", { pollingId, progress: response.data.progress }) }) }, 500) commit("CREATE_POLLING", { pollingId, pollTimer }) }) }, UPDATE_ACTIVE_REQUESTS({ commit }, { add }) { commit("UPDATE_ACTIVE_REQUESTS", { addNewRequest: add }) }, PATCH_COURSE({ commit, dispatch }, { courseName, course, options }) { return Courses.patch(courseName, course, options) .then((response) => { return dispatch("FETCH_COURSE", { courseName }) }) + }, + + SET_ERROR({ commit }, { error }) { + commit("EMPTY_ERROR") + commit("SET_ERROR", { error: error }) } } diff --git a/src/store/mutations.js b/src/store/mutations.js index 89caff5..b23262e 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -1,65 +1,69 @@ import Vue from "vue" export const mutations = { SET_ROOT_CATEGORIES(state, { categories }) { state.rootCategories = categories }, SET_CHAPTER(state, { chapter }) { Vue.set(state.chapters, chapter._id, chapter) }, SET_NAVIGATION_LINKS(state, { navigationLinks }) { state.navigationLinks = navigationLinks }, SET_CATEGORY(state, { category }) { Vue.set(state.categories, category.name, category) }, SET_COURSE(state, { course }) { Vue.set(state.courses, course._id, course) }, SET_PAGE(state, { page }) { Vue.set(state.pages, page._id, page) }, SET_ERROR(state, { error }) { state.error = Object.assign({}, error) }, + EMPTY_ERROR(state) { + state.error = null + }, + CLEAR_ERROR(state) { state.error = null }, CLEAR_COURSES(state) { state.courses = {} }, CREATE_POLLING(state, { pollingId, pollTimer }) { Vue.set(state.pollingOperations, pollingId, { title: pollingId, id: pollingId, progress: 0, timer: pollTimer }) }, UPDATE_POLLING(state, { pollingId, progress }) { Vue.set(state.pollingOperations[pollingId], "progress", progress) }, DELETE_POLLING(state, { id }) { clearTimeout(state.pollingOperations[id].timer) Vue.delete(state.pollingOperations, id) }, UPDATE_ACTIVE_REQUESTS(state, { addNewRequest }) { state.activeApiRequests += addNewRequest }, SET_META(state, { meta }) { state.meta = meta } }