From ca386163957da4678883202082b21ce01bd73e83 Mon Sep 17 00:00:00 2001 From: jedi Date: Sun, 29 Dec 2019 17:04:03 +0100 Subject: [PATCH] remember last box --- src/components/AddItemModal.vue | 3 +++ src/components/inputs/InputCombo.vue | 3 +-- src/store/index.js | 10 ++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/AddItemModal.vue b/src/components/AddItemModal.vue index bee1150..ff65ddb 100644 --- a/src/components/AddItemModal.vue +++ b/src/components/AddItemModal.vue @@ -23,6 +23,9 @@ export default { data: () => ({ item: {} }), + created() { + this.item = {box: this.$store.state.lastUsed.box || ''}; + }, methods: { saveNewItem() { this.$store.dispatch('postItem', this.item); diff --git a/src/components/inputs/InputCombo.vue b/src/components/inputs/InputCombo.vue index 2dff6bf..053461c 100644 --- a/src/components/inputs/InputCombo.vue +++ b/src/components/inputs/InputCombo.vue @@ -53,7 +53,7 @@ export default { sortedOptions: ({options, nameKey}) => options.sort((a, b) => a[nameKey].localeCompare(b[nameKey], 'en', { numeric: true })), }, watch: { - internalName(newValue, oldValue) { + internalName(newValue) { if (this.isValid) { if(!this.selectedOption || newValue!=this.selectedOption[this.nameKey]){ this.selectedOption = this.options.filter(e => e[this.nameKey] === newValue)[0]; @@ -61,7 +61,6 @@ export default { this.model[this.nameKey] = this.selectedOption[this.nameKey]; this.model[this.uniqueKey] = this.selectedOption[this.uniqueKey]; } - console.log(oldValue, newValue, this.isValid); } }, methods: { diff --git a/src/store/index.js b/src/store/index.js index 4cc3a71..7b14eaf 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -2,7 +2,7 @@ import Vue from 'vue'; import Vuex from 'vuex'; import AxiosBootstrap from 'axios'; import config from '../config'; -//import * as _ from 'lodash/fp'; +import * as _ from 'lodash/fp'; import router from '../router'; import * as base64 from 'base-64'; @@ -44,7 +44,8 @@ const store = new Vuex.Store({ layout: 'cards', loadedItems: [], loadedBoxes: [], - toasts: [] + toasts: [], + lastUsed: localStorage.getItem('lf_lastUsed') || {}, }, getters: { getEventSlug: state => state.route && state.route.params.event? state.route.params.event : state.events.length ? state.events[0].slug : '36C3', @@ -53,6 +54,10 @@ const store = new Vuex.Store({ getBoxes: state => state.loadedBoxes }, mutations: { + updateLastUsed(state, diff) { + state.lastUsed = _.extend(state.lastUsed, diff); + localStorage.setItem('lf_lastUsed', state.lastUsed); + }, replaceEvents(state, events) { state.events = events; }, @@ -129,6 +134,7 @@ const store = new Vuex.Store({ commit('removeItem',item); }, async postItem({ commit, getters }, item) { + commit('updateLastUsed',{box: item.box}); const { data } = await axios.post(`/1/${getters.getEventSlug}/item`, item); commit('appendItem', data); }