aboutsummaryrefslogtreecommitdiff
path: root/resources/js
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-03-21 18:05:38 +0100
committerMateja <mail@matejamaric.com>2021-03-21 18:05:38 +0100
commit2809ccf7272d4b77c5eb3f3d6599143dc4678d70 (patch)
tree1c46dd969ecbdb4b89e69051cab2395e2e510afe /resources/js
parent09ee04d39911f169457567c869d732a11387651a (diff)
downloadyota-laravel-2809ccf7272d4b77c5eb3f3d6599143dc4678d70.tar.gz
yota-laravel-2809ccf7272d4b77c5eb3f3d6599143dc4678d70.zip
Work on `reservation.vue` component.
- Move Lodash cloneDeep to Vuex store.
Diffstat (limited to 'resources/js')
-rw-r--r--resources/js/components/reservation.vue14
-rw-r--r--resources/js/store.js18
2 files changed, 25 insertions, 7 deletions
diff --git a/resources/js/components/reservation.vue b/resources/js/components/reservation.vue
index 5389e1a..ec430ab 100644
--- a/resources/js/components/reservation.vue
+++ b/resources/js/components/reservation.vue
@@ -25,21 +25,21 @@ export default {
props: [ 'reservationIndex' ],
data() {
return {
- reservation: {}
+ reservation: this.$store.getters.getDataRow(this.reservationIndex)
}
},
- mounted() {
- this.reservation = _.cloneDeep(this.$store.getters.getData[this.reservationIndex]);
- },
methods: {
updateRow() {
-
+ this.$store.dispatch('pushReservation', {
+ index: this.reservationIndex,
+ reservation: this.reservation
+ });
},
restoreRow() {
- this.reservation = _.cloneDeep(this.$store.getters.getData[this.reservationIndex]);
+ this.reservation = this.$store.getters.getDataRow(this.reservationIndex);
},
deleteRow() {
-
+ this.$store.dispatch('removeReservation', this.reservationIndex);
}
}
}
diff --git a/resources/js/store.js b/resources/js/store.js
index 345b866..e0c4383 100644
--- a/resources/js/store.js
+++ b/resources/js/store.js
@@ -17,6 +17,9 @@ export default new Vuex.Store({
},
getData(state) {
return state.data;
+ },
+ getDataRow(state) {
+ return (index) => _.cloneDeep(state.data[index]);
}
},
mutations: {
@@ -28,6 +31,12 @@ export default new Vuex.Store({
},
setData(state, data) {
state.data = data;
+ },
+ setDataRow(state, row) {
+ state.data[row.index] = _.cloneDeep(row.data);
+ },
+ removeDataRow(state, index) {
+ state.data.splice(index, 1);
}
},
actions: {
@@ -54,6 +63,15 @@ export default new Vuex.Store({
}).catch(error => {
console.log(error);
});
+ },
+ async pushReservation(context, data) {
+ context.commit('setDataRow', {
+ index: data.index,
+ data: data.reservation
+ });
+ },
+ async removeReservation(context, index) {
+ context.commit('removeDataRow', index);
}
}
});