diff --git a/README.md b/README.md
index af3ef0a..3708ac0 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,7 @@
# Preparations
+### Оправдание
+Код не самый лучший. Делалось все на скорую руку
+
### Demo
http://preparations.herokuapp.com
diff --git a/package.json b/package.json
index f4150cb..d756a5f 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,8 @@
"vue": "^2.6.10",
"vue-router": "^3.0.3",
"vuetify": "^1.5.14",
- "vuex": "^3.0.1"
+ "vuex": "^3.0.1",
+ "vuex-persistedstate": "^2.5.4"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.1.1",
diff --git a/src/components/CheckCard.vue b/src/components/CheckCard.vue
index d1750be..1172f9f 100644
--- a/src/components/CheckCard.vue
+++ b/src/components/CheckCard.vue
@@ -1,10 +1,15 @@
+
+
+
{{ preparation.name }}
@@ -28,6 +33,17 @@
???
+
+
+ Я тупая
+ Я самая умная и красивая
+
@@ -40,17 +56,18 @@ export default {
methods: {
checkMyself() {
this.$emit('check-myself')
+ },
+ success() {
+ this.$emit('success')
+ },
+ wrong() {
+ this.$emit('wrong', this.preparation.id)
}
}
}
diff --git a/src/components/CustomCard.vue b/src/components/CustomCard.vue
index 828d3fd..a30d399 100644
--- a/src/components/CustomCard.vue
+++ b/src/components/CustomCard.vue
@@ -14,17 +14,35 @@
{{ preparation.portion }}
-
+
+
+ Повторить
+ Удалить
+
diff --git a/src/main.js b/src/main.js
index 5d73a49..58a28fd 100644
--- a/src/main.js
+++ b/src/main.js
@@ -3,7 +3,7 @@ import Vuetify from 'vuetify'
import App from './App.vue'
import router from './router'
-import store from './store'
+import store from './store/'
import 'vuetify/dist/vuetify.min.css'
diff --git a/src/router.js b/src/router.js
index 17b529f..c2db303 100644
--- a/src/router.js
+++ b/src/router.js
@@ -5,7 +5,7 @@ import Home from './views/Home.vue'
Vue.use(Router)
export default new Router({
- mode: 'history',
+ // mode: 'history',
base: process.env.BASE_URL,
routes: [
{
diff --git a/src/store.js b/src/store.js
deleted file mode 100644
index 3c7424e..0000000
--- a/src/store.js
+++ /dev/null
@@ -1,16 +0,0 @@
-import Vue from 'vue'
-import Vuex from 'vuex'
-
-Vue.use(Vuex)
-
-export default new Vuex.Store({
- state: {
-
- },
- mutations: {
-
- },
- actions: {
-
- }
-})
diff --git a/src/store/index.js b/src/store/index.js
new file mode 100644
index 0000000..00459d8
--- /dev/null
+++ b/src/store/index.js
@@ -0,0 +1,17 @@
+import Vue from 'vue'
+import Vuex from 'vuex'
+import createPersistedState from 'vuex-persistedstate'
+
+import preparationsStore from './preparations'
+
+Vue.use(Vuex);
+const store = new Vuex.Store({
+ plugins: [
+ createPersistedState()
+ ],
+ modules: {
+ preparationsStore,
+ }
+})
+
+export default store;
diff --git a/src/store/preparations.js b/src/store/preparations.js
new file mode 100644
index 0000000..353ee6a
--- /dev/null
+++ b/src/store/preparations.js
@@ -0,0 +1,37 @@
+const preparationsStore = {
+ namespaced: true,
+ state: {
+ preparationsIdToRepeat: []
+ },
+ mutations: {
+ pushPreparation(state, preparationId) {
+ state.preparationsIdToRepeat.push(preparationId)
+ },
+ removePreparaion(state, preparationId) {
+ const index = state.preparationsIdToRepeat.findIndex(el => {
+ return el === preparationId
+ })
+
+ state.preparationsIdToRepeat.splice(index, 1)
+ }
+ },
+ actions: {
+ pushPreparation({state, commit}, preparationId) {
+ state.preparationsIdToRepeat.find(id => {
+ return id == preparationId
+ })
+ ? null
+ : commit('pushPreparation', preparationId)
+ },
+ removePreparaion({state, commit}, preparationId) {
+ commit('removePreparaion', preparationId)
+ }
+ },
+ getters: {
+ preparationsIdToRepeat(state) {
+ return state.preparationsIdToRepeat
+ }
+ }
+};
+
+export default preparationsStore
diff --git a/src/views/Check.vue b/src/views/Check.vue
index 21b19fd..3dc0e28 100644
--- a/src/views/Check.vue
+++ b/src/views/Check.vue
@@ -1,5 +1,6 @@
+
Тест
@@ -7,13 +8,31 @@
:preparation="preparations[this.randomItem]"
:isVisible="isVisible"
@check-myself="checkMyself"
+ @wrong="addToForgotList"
+ @success="success"
/>
-
+
+
+
Обязательно повторить
+
+
+
+
+
+
@@ -21,9 +40,12 @@
import preparations from '@/assets/preparations'
import PreparationForm from '@/components/PreparationForm'
import CheckCard from '@/components/CheckCard'
+import CustomCard from '@/components/CustomCard'
+
+import {mapActions, mapGetters} from 'vuex';
export default {
- name: 'home',
+ name: 'check',
data() {
return {
preparations: [],
@@ -34,9 +56,30 @@ export default {
},
components: {
CheckCard,
+ CustomCard,
PreparationForm,
},
+ computed: {
+ ...mapGetters('preparationsStore', [
+ 'preparationsIdToRepeat'
+ ]),
+ preparationsToRepeat() {
+ return this.preparationsIdToRepeat
+ .map(id => {
+ return preparations.find(preparation => {
+ return preparation.id === id
+ })
+ })
+ .sort((a, b) => {
+ return +a.id - +b.id
+ })
+ }
+ },
methods: {
+ ...mapActions('preparationsStore', [
+ 'pushPreparation',
+ 'removePreparaion'
+ ]),
setRandomItem(){
this.randomItem = Math.round(Math.random()*this.preparations.length)
},
@@ -45,17 +88,17 @@ export default {
this.isVisible = false
},
checkMyself() {
- console.log(this.clicks)
- if(this.clicks === 0) {
- this.isVisible = true;
- this.clicks = 1
- return;
- }
-
- if(this.clicks === 1) {
- this.nextItem()
- this.clicks = 0;
- }
+ this.isVisible = true;
+ },
+ addToForgotList(preparationId) {
+ this.nextItem(),
+ this.pushPreparation(preparationId)
+ },
+ removeFromForgotList(preparationId) {
+ this.removePreparaion(preparationId)
+ },
+ success() {
+ this.nextItem()
}
},
mounted() {
@@ -64,3 +107,13 @@ export default {
}
}
+
+
diff --git a/src/views/Home.vue b/src/views/Home.vue
index edb7eaa..f825b3b 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -24,6 +24,8 @@
>
@@ -45,6 +47,8 @@ import CustomCard from '@/components/CustomCard'
import NotFound from '@/components/NotFound'
import { filteredItems } from '@/assets/helpers'
+import { mapAtions, mapActions } from 'vuex'
+
export default {
name: 'home',
data() {
@@ -63,6 +67,9 @@ export default {
NotFound
},
methods: {
+ ...mapActions('preparationsStore', [
+ 'pushPreparation',
+ ]),
filterPreps(type = this.type, amount = this.amount) {
this.filteredPreparations = this.preparations
.filter(el => el.name.indexOf(type) > -1 ? true : false)
@@ -72,6 +79,9 @@ export default {
: parseInt(el.amount.match(/\d+/)) === parseInt(amount)
})
},
+ addPreparationToForgotList(preparationId) {
+ this.pushPreparation(preparationId)
+ },
setType(type) {
this.type = type
this.filterPreps();
diff --git a/yarn.lock b/yarn.lock
index 82c4300..97922d9 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2540,6 +2540,11 @@ deepmerge@^1.5.2:
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-1.5.2.tgz#10499d868844cdad4fee0842df8c7f6f0c95a753"
integrity sha512-95k0GDqvBjZavkuvzx/YqVLv/6YYa17fz6ILMSf7neqQITCPbnfEnQvEgMPNjH4kgobe7+WIL0yJEHku+H3qtQ==
+deepmerge@^2.1.0:
+ version "2.2.1"
+ resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.2.1.tgz#5d3ff22a01c00f645405a2fbc17d0778a1801170"
+ integrity sha512-R9hc1Xa/NOBi9WRVUWg19rl1UB7Tt4kuPd+thNJgFZoxXsTz7ncaPaeIm+40oSGuP33DfMb4sZt1QIGiJzC4EA==
+
default-gateway@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/default-gateway/-/default-gateway-4.2.0.tgz#167104c7500c2115f6dd69b0a536bb8ed720552b"
@@ -6610,6 +6615,11 @@ shell-quote@^1.6.1:
array-reduce "~0.0.0"
jsonify "~0.0.0"
+shvl@^1.3.0:
+ version "1.3.1"
+ resolved "https://registry.yarnpkg.com/shvl/-/shvl-1.3.1.tgz#6c20a17b4a20b08e9f8cab60c50a92229fcc176e"
+ integrity sha512-+rRPP46hloYUAEImJcqprUgXu+05Ikqr4h4V+w5i2zJy37nAqtkQKufs3+3S2fDq6JNRrHMIQhB/Vaex+jgAAw==
+
signal-exit@^3.0.0, signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
@@ -7554,6 +7564,14 @@ vuetify@^1.5.14:
resolved "https://registry.yarnpkg.com/vuetify/-/vuetify-1.5.14.tgz#ff67d0b8a398be5297da159b6cd1b31f4d2898b8"
integrity sha512-7iM+TfghR/wu/Gl+k37lKr0N8Ddr6SxzqHtoK1dIyHgCH6SJRkpaXPw2MC5/FsAg9aUDJbYNWrzSeu5eHw+Q/w==
+vuex-persistedstate@^2.5.4:
+ version "2.5.4"
+ resolved "https://registry.yarnpkg.com/vuex-persistedstate/-/vuex-persistedstate-2.5.4.tgz#a19710ad7f9a08cea4e65fc585924d9fdac7384a"
+ integrity sha512-XYJhKIwO+ZVlTaXyxKxnplrJ88Fnvk5aDw753bxzRw5/yMKLQ6lq9CDCBex2fwZaQcLibhtgJOxGCHjy9GLSlQ==
+ dependencies:
+ deepmerge "^2.1.0"
+ shvl "^1.3.0"
+
vuex@^3.0.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/vuex/-/vuex-3.1.1.tgz#0c264bfe30cdbccf96ab9db3177d211828a5910e"