mirror of
https://github.com/Lissy93/dashy.git
synced 2024-12-29 03:45:20 +03:00
🚧 You can now save items to VueX store, neat!
This commit is contained in:
parent
677f0eea4e
commit
f1fc013457
@ -7,22 +7,22 @@
|
||||
classes="dashy-modal edit-item"
|
||||
@closed="modalClosed"
|
||||
>
|
||||
<h3>Edit Item</h3>
|
||||
<form>
|
||||
<div class="row" v-for="row in formData" :key="row.name">
|
||||
<h3>Edit Item</h3>
|
||||
<div class="row" v-for="(row, index) in formData" :key="row.name">
|
||||
<Input
|
||||
:label="row.name"
|
||||
:value="row.value"
|
||||
v-model="formData[index].value"
|
||||
:description="row.description"
|
||||
:label="row.name"
|
||||
layout="horizontal"
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
<Button :click="saveItem">Save</Button>
|
||||
</modal>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Input from '@/components/FormElements/Input';
|
||||
import Button from '@/components/FormElements/Button';
|
||||
import StoreKeys from '@/utils/StoreMutations';
|
||||
import DashySchema from '@/utils/ConfigSchema';
|
||||
import { modalNames } from '@/utils/defaults';
|
||||
@ -43,6 +43,7 @@ export default {
|
||||
computed: {},
|
||||
components: {
|
||||
Input,
|
||||
Button,
|
||||
},
|
||||
mounted() {
|
||||
this.item = this.getItemFromState(this.itemId);
|
||||
@ -66,6 +67,13 @@ export default {
|
||||
getItemFromState(id) {
|
||||
return this.$store.getters.getItemById(id);
|
||||
},
|
||||
saveItem() {
|
||||
const newItem = {};
|
||||
this.formData.forEach((row) => {
|
||||
newItem[row.name] = row.value;
|
||||
});
|
||||
this.$store.commit(StoreKeys.UPDATE_ITEM, { newItem, itemId: this.itemId });
|
||||
},
|
||||
modalClosed() {
|
||||
this.$store.commit(StoreKeys.SET_MODAL_OPEN, false);
|
||||
this.$emit('closeEditMenu');
|
||||
@ -89,6 +97,10 @@ export default {
|
||||
&:not(:last-child) {
|
||||
border-bottom: 1px dotted var(--config-settings-color);
|
||||
}
|
||||
.input-container input.input-field {
|
||||
font-size: 1rem;
|
||||
padding: 0.35rem 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
19
src/store.js
19
src/store.js
@ -8,7 +8,12 @@ import filterUserSections from '@/utils/CheckSectionVisibility';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
const { UPDATE_CONFIG, SET_MODAL_OPEN, SET_LANGUAGE } = Keys;
|
||||
const {
|
||||
UPDATE_CONFIG,
|
||||
SET_MODAL_OPEN,
|
||||
SET_LANGUAGE,
|
||||
UPDATE_ITEM,
|
||||
} = Keys;
|
||||
|
||||
const store = new Vuex.Store({
|
||||
state: {
|
||||
@ -54,6 +59,18 @@ const store = new Vuex.Store({
|
||||
[SET_MODAL_OPEN](state, modalOpen) {
|
||||
state.modalOpen = modalOpen;
|
||||
},
|
||||
[UPDATE_ITEM](state, payload) {
|
||||
const { itemId, newItem } = payload;
|
||||
const newConfig = state.config;
|
||||
newConfig.sections.forEach((section, secIndex) => {
|
||||
section.items.forEach((item, itemIndex) => {
|
||||
if (item.id === itemId) {
|
||||
newConfig.sections[secIndex].items[itemIndex] = newItem;
|
||||
}
|
||||
});
|
||||
});
|
||||
state.config = newConfig;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
/* Called when app first loaded. Reads config and sets state */
|
||||
|
@ -3,6 +3,7 @@ const KEY_NAMES = [
|
||||
'UPDATE_CONFIG',
|
||||
'SET_MODAL_OPEN',
|
||||
'SET_LANGUAGE',
|
||||
'UPDATE_ITEM',
|
||||
];
|
||||
|
||||
// Convert array of key names into an object, and export
|
||||
|
Loading…
Reference in New Issue
Block a user