From 23ff2f156822113aaf36c381e0c1960edef7506b Mon Sep 17 00:00:00 2001 From: f0x Date: Fri, 16 Sep 2022 21:18:36 +0200 Subject: [PATCH] Account.source default values --- .../settings-panel/redux/reducers/user.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/web/source/settings-panel/redux/reducers/user.js b/web/source/settings-panel/redux/reducers/user.js index 5db312d34..b4463c9f9 100644 --- a/web/source/settings-panel/redux/reducers/user.js +++ b/web/source/settings-panel/redux/reducers/user.js @@ -18,8 +18,9 @@ "use strict"; -const {createSlice} = require("@reduxjs/toolkit"); +const { createSlice } = require("@reduxjs/toolkit"); const d = require("dotty"); +const defaultValue = require("default-value"); module.exports = createSlice({ name: "user", @@ -28,20 +29,22 @@ module.exports = createSlice({ settings: {} }, reducers: { - setAccount: (state, {payload}) => { - if (payload.source != undefined && payload.source.language != undefined) { - payload.source.language = payload.source.language.toUpperCase(); - } + setAccount: (state, { payload }) => { + payload.source = defaultValue(payload.source, {}); + payload.source.language = defaultValue(payload.source.language.toUpperCase(), "EN"); + payload.source.status_format = defaultValue(payload.source.status_format, "plain"); + payload.source.sensitive = defaultValue(payload.source.sensitive, false); + state.profile = payload; // /user/settings only needs a copy of the 'source' obj state.settings = { source: payload.source }; }, - setProfileVal: (state, {payload: [key, val]}) => { + setProfileVal: (state, { payload: [key, val] }) => { d.put(state.profile, key, val); }, - setSettingsVal: (state, {payload: [key, val]}) => { + setSettingsVal: (state, { payload: [key, val] }) => { d.put(state.settings, key, val); } }