diff --git a/src/admin/components/About/About.vue b/src/admin/components/About/About.vue
index 36f7b02..b3feecc 100644
--- a/src/admin/components/About/About.vue
+++ b/src/admin/components/About/About.vue
@@ -8,23 +8,26 @@
text="Добавить группу"
size="small"
type='button'
- @click="showAddSkillGroup = true")
+ @click="showAddGroup = true")
.about__content
.container.about__content-container
ul.skill-group__list
- li.skill-group__item(v-if="showAddSkillGroup")
- SkillGroup(:value="emptySkillGroup")
+ li.skill-group__item(v-if="showAddGroup")
+ SkillGroup(
+ :skillGroup="category"
+ @hide="hideAddGroup")
li(
- v-for="skillGroup in skillGroups"
- :key="skillGroup.id"
+ v-for="category in categories"
+ :key="category.id"
).skill-group__item
SkillGroup(
- :value="skillGroup"
+ :skillGroup="category"
)
\ No newline at end of file
diff --git a/src/admin/store/modules/categories.js b/src/admin/store/modules/categories.js
index f9843a1..c8c14d2 100644
--- a/src/admin/store/modules/categories.js
+++ b/src/admin/store/modules/categories.js
@@ -4,15 +4,117 @@ export default {
namespaced: true,
state: {
- user: {}
- },
-
- getters: {
+ categories: []
},
mutations: {
+ setCategories (state, categories) {
+ state.categories = categories
+ },
+
+ addCategory (state, categories) {
+ state.categories = [categories, ...state.categories]
+ },
+
+ editCategory (state, category) {
+ state.categories = state.categories.map(item => item.id === category.id ? category : item)
+ },
+
+ removeCategory (state, categoryId) {
+ state.categories = state.categories.filter(category => category.id !== categoryId)
+ },
+
+ addSkill (state, skill) {
+ state.categories = state.categories.map(category => {
+ if (category.id === skill.category) {
+ const skills = category.skills || []
+ category.skills = [...skills, skill]
+ }
+
+ return category
+ })
+ },
+
+ editSkill (state, skill) {
+ const category = state.categories.find(category => category.id === skill.category)
+ if (category) {
+ const skills = category.skills
+ category.skills = skills.map(el => el.id === skill.id ? skill : el)
+ }
+ },
+
+ removeSkill (state, skill) {
+ const category = state.categories.find(category => category.id === skill.category)
+ if (category) {
+ const skills = category.skills
+ category.skills = skills.filter(el => el.id !== skill.id)
+ }
+ }
},
actions: {
+ async loadCategories ({ commit }, userId) {
+ try {
+ const { data } = await axios.get(`/categories/${userId}`)
+ commit('setCategories', data)
+ } catch (error) {
+ console.log(error)
+ }
+ },
+
+ async saveCategory ({ commit }, title) {
+ try {
+ const { data } = await axios.post('/categories', { title })
+ commit('addCategory', data)
+ } catch (error) {
+ throw new Error(error)
+ console.log(error)
+ }
+ },
+
+ async updateCategory ({ commit }, category) {
+ try {
+ const { data } = await axios.post(`/categories/${category.id}`, { title: category.category })
+ commit('editCategory', data.category)
+ } catch (error) {
+ console.log(error)
+ }
+ },
+
+ async deleteCategory ({ commit }, categoryId) {
+ try {
+ await axios.delete(`/categories/${categoryId}`)
+ commit('removeCategory', categoryId)
+ } catch (error) {
+ console.log(error)
+ }
+ },
+
+ async saveSkill ({ commit }, skill) {
+ try {
+ const { data } = await axios.post('/skills', skill);
+ commit('addSkill', data);
+ } catch (error) {
+ console.log(error)
+ }
+ },
+
+ async deleteSkill ({ commit }, skill) {
+ try {
+ await axios.delete(`/skills/${ skill.id }`);
+ commit('removeSkill', skill);
+ } catch (error) {
+ console.log(error)
+ }
+ },
+
+ async updateSkill ({ commit }, skill) {
+ try {
+ const { data } = await axios.post(`/skills/${ skill.id }`, skill);
+ commit('editSkill', data.skill);
+ } catch (error) {
+ console.log(error)
+ }
+ }
}
}
\ No newline at end of file