From e0f51667eb19505cccc34d858218f403d4d8d31c Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Tue, 5 Sep 2023 07:33:56 +0200 Subject: [PATCH] fix: fix some issues with the presets (#1529) --- src/store/gui/presets/getters.ts | 34 ++++++++++++++++-------------- src/store/gui/presets/mutations.ts | 7 ++---- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/store/gui/presets/getters.ts b/src/store/gui/presets/getters.ts index 02c05d419..a00420a0b 100644 --- a/src/store/gui/presets/getters.ts +++ b/src/store/gui/presets/getters.ts @@ -33,22 +33,24 @@ export const getters: GetterTree = { text: '0 °C', }) - if ('presets' in state) { - Object.keys(state.presets).forEach((id: string) => { - const preset = state.presets[id] - - if ( - payload.name in preset.values && - preset.values[payload.name].bool && - output.findIndex((entry: preset) => entry.value === preset.values[payload.name].value) === -1 - ) { - output.push({ - value: preset.values[payload.name].value, - text: preset.values[payload.name].value + ' °C', - }) - } - }) - } + // return only 0 entry, if there is no presets set + if (!('presets' in state)) return output + + Object.keys(state.presets).forEach((id: string) => { + const preset = state.presets[id] + + if ( + payload.name in preset.values && + preset.values[payload.name].bool && + output.findIndex((entry: preset) => entry.value === preset.values[payload.name].value) === -1 + ) { + output.push({ + // @ts-ignore + value: parseFloat(preset.values[payload.name].value), + text: preset.values[payload.name].value + ' °C', + }) + } + }) return output.sort((a: preset, b: preset) => { if (a.value > b.value) return -1 diff --git a/src/store/gui/presets/mutations.ts b/src/store/gui/presets/mutations.ts index 1a4085689..ebb9e80c7 100644 --- a/src/store/gui/presets/mutations.ts +++ b/src/store/gui/presets/mutations.ts @@ -22,12 +22,9 @@ export const mutations: MutationTree = { }, update(state, payload) { - if (payload.id in state.presets) { - const preset = { ...state.presets[payload.id] } - Object.assign(preset, payload.values) + if (!(payload.id in state.presets)) return - Vue.set(state.presets, payload.id, preset) - } + Vue.set(state.presets, payload.id, payload.values) }, updateCooldownGcode(state, payload) {