From 8f26f1350efd578ddf4260957343fa05745f5ef5 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Thu, 27 Apr 2023 21:58:27 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Improve=20s?= =?UTF-8?q?ettings=20ctx,=20added=20`updateCurrentValue`=20&=20`beforeSave?= =?UTF-8?q?`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/app/src/pages/settings/index.jsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/app/src/pages/settings/index.jsx b/packages/app/src/pages/settings/index.jsx index b8df5864..7a61ab77 100755 --- a/packages/app/src/pages/settings/index.jsx +++ b/packages/app/src/pages/settings/index.jsx @@ -4,6 +4,7 @@ import { SliderPicker } from "react-color" import { Translation } from "react-i18next" import classnames from "classnames" import config from "config" +import useUrlQueryActiveKey from "hooks/useUrlQueryActiveKey" import AuthModel from "models/auth" @@ -116,6 +117,10 @@ const SettingItem = (props) => { await window.app.cores.settings.set(item.id, updateValue) } + if (item.storaged && typeof item.beforeSave === "function") { + await item.beforeSave(updateValue) + } + if (typeof item.emitEvent !== "undefined") { let emissionPayload = updateValue @@ -292,6 +297,7 @@ const SettingItem = (props) => { item.props["disabled"] = disabled const elementsCtx = { + updateCurrentValue: (value) => setValue(value), currentValue: value, dispatchUpdate, onUpdateItem, @@ -337,6 +343,7 @@ const SettingItem = (props) => { onClick={handleOnClick} icon={action.icon && createIconRender(action.icon)} type={action.type ?? "round"} + disabled={item.props.disabled} > {action.title} @@ -551,7 +558,11 @@ const generateMenuItems = () => { } export default () => { - const [activeKey, setActiveKey] = React.useState("general") + const [activeKey, setActiveKey] = useUrlQueryActiveKey({ + defaultKey: "general", + queryKey: "tab" + }) + const [menuItems, setMenuItems] = React.useState([]) const onChangeTab = (event) => {