diff --git a/src/store/modules/normalizers.js b/src/store/modules/normalizers.js index dcf9bdc8..1df1fd08 100644 --- a/src/store/modules/normalizers.js +++ b/src/store/modules/normalizers.js @@ -1,3 +1,26 @@ +export const checkPartialUpdate = (settings, updatedSettings, description) => { + return Object.keys(updatedSettings).reduce((acc, group) => { + acc[group] = Object.keys(updatedSettings[group]).reduce((acc, key) => { + debugger + if (!partialUpdate(group, key)) { + const updated = Object.keys(settings[group][key]).reduce((acc, settingName) => { + const setting = description + .find(element => element.group === group && element.key === key).children + .find(child => child.key === settingName) + const type = setting ? setting.type : '' + acc[settingName] = [type, settings[group][key][settingName]] + return acc + }, {}) + acc[key] = updated + return acc + } + acc[key] = updatedSettings[group][key] + return acc + }, {}) + return acc + }, {}) +} + const getCurrentValue = (object, keys) => { if (keys.length === 0) { return object @@ -103,7 +126,7 @@ const parseProxyUrl = value => { return { socks5: false, host: null, port: null } } -export const partialUpdate = (group, key) => { +const partialUpdate = (group, key) => { if (group === ':auto_linker' && key === ':opts') { return false } diff --git a/src/store/modules/settings.js b/src/store/modules/settings.js index 406bd46d..7efc29b5 100644 --- a/src/store/modules/settings.js +++ b/src/store/modules/settings.js @@ -1,5 +1,5 @@ import { fetchDescription, fetchSettings, removeSettings, updateSettings, uploadMedia } from '@/api/settings' -import { parseNonTuples, parseTuples, partialUpdate, valueHasTuples, wrapUpdatedSettings } from './normalizers' +import { checkPartialUpdate, parseNonTuples, parseTuples, valueHasTuples, wrapUpdatedSettings } from './normalizers' const settings = { state: { @@ -70,27 +70,11 @@ const settings = { await removeSettings(configs, getters.authHost, getters.token) }, async SubmitChanges({ getters, commit, state }) { - const updatedData = Object.keys(state.updatedSettings).reduce((acc, group) => { - acc[group] = Object.keys(state.updatedSettings[group]).reduce((acc, key) => { - if (!partialUpdate(group, key)) { - const updated = Object.keys(state.settings[group][key]).reduce((acc, settingName) => { - const settingType = state.description - .find(element => element.group === group && element.key === key).children - .find(child => child.key === settingName).type - acc[settingName] = [settingType, state.settings[group][key][settingName]] - return acc - }, {}) - acc[key] = updated - return acc - } - acc[key] = state.updatedSettings[group][key] - return acc - }, {}) - return acc - }, {}) + const updatedData = checkPartialUpdate(state.settings, state.updatedSettings, state.description) const configs = Object.keys(updatedData).reduce((acc, group) => { return [...acc, ...wrapUpdatedSettings(group, updatedData[group], state.settings)] }, []) + const response = await updateSettings(configs, getters.authHost, getters.token) commit('SET_SETTINGS', response.data.configs) commit('CLEAR_UPDATED_SETTINGS')