remember last box

This commit is contained in:
j3d1 2019-12-29 17:04:03 +01:00
parent 7141c8e34e
commit ca38616395
3 changed files with 12 additions and 4 deletions

View file

@ -23,6 +23,9 @@ export default {
data: () => ({ data: () => ({
item: {} item: {}
}), }),
created() {
this.item = {box: this.$store.state.lastUsed.box || ''};
},
methods: { methods: {
saveNewItem() { saveNewItem() {
this.$store.dispatch('postItem', this.item); this.$store.dispatch('postItem', this.item);

View file

@ -53,7 +53,7 @@ export default {
sortedOptions: ({options, nameKey}) => options.sort((a, b) => a[nameKey].localeCompare(b[nameKey], 'en', { numeric: true })), sortedOptions: ({options, nameKey}) => options.sort((a, b) => a[nameKey].localeCompare(b[nameKey], 'en', { numeric: true })),
}, },
watch: { watch: {
internalName(newValue, oldValue) { internalName(newValue) {
if (this.isValid) { if (this.isValid) {
if(!this.selectedOption || newValue!=this.selectedOption[this.nameKey]){ if(!this.selectedOption || newValue!=this.selectedOption[this.nameKey]){
this.selectedOption = this.options.filter(e => e[this.nameKey] === newValue)[0]; 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.nameKey] = this.selectedOption[this.nameKey];
this.model[this.uniqueKey] = this.selectedOption[this.uniqueKey]; this.model[this.uniqueKey] = this.selectedOption[this.uniqueKey];
} }
console.log(oldValue, newValue, this.isValid);
} }
}, },
methods: { methods: {

View file

@ -2,7 +2,7 @@ import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import AxiosBootstrap from 'axios'; import AxiosBootstrap from 'axios';
import config from '../config'; import config from '../config';
//import * as _ from 'lodash/fp'; import * as _ from 'lodash/fp';
import router from '../router'; import router from '../router';
import * as base64 from 'base-64'; import * as base64 from 'base-64';
@ -44,7 +44,8 @@ const store = new Vuex.Store({
layout: 'cards', layout: 'cards',
loadedItems: [], loadedItems: [],
loadedBoxes: [], loadedBoxes: [],
toasts: [] toasts: [],
lastUsed: localStorage.getItem('lf_lastUsed') || {},
}, },
getters: { getters: {
getEventSlug: state => state.route && state.route.params.event? state.route.params.event : state.events.length ? state.events[0].slug : '36C3', 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 getBoxes: state => state.loadedBoxes
}, },
mutations: { mutations: {
updateLastUsed(state, diff) {
state.lastUsed = _.extend(state.lastUsed, diff);
localStorage.setItem('lf_lastUsed', state.lastUsed);
},
replaceEvents(state, events) { replaceEvents(state, events) {
state.events = events; state.events = events;
}, },
@ -129,6 +134,7 @@ const store = new Vuex.Store({
commit('removeItem',item); commit('removeItem',item);
}, },
async postItem({ commit, getters }, item) { async postItem({ commit, getters }, item) {
commit('updateLastUsed',{box: item.box});
const { data } = await axios.post(`/1/${getters.getEventSlug}/item`, item); const { data } = await axios.post(`/1/${getters.getEventSlug}/item`, item);
commit('appendItem', data); commit('appendItem', data);
} }