added settings page

This commit is contained in:
SrGooglo 2023-02-24 14:41:34 +00:00
parent 21e0057493
commit 79711c64d8
2 changed files with 35 additions and 21 deletions

View File

@ -63,7 +63,7 @@ const SettingItem = (props) => {
return false return false
} }
} else { } else {
const storagedValue = await window.app.settings.get(item.id) const storagedValue = await window.app.cores.settings.get(item.id)
if (typeof updateValue === "undefined") { if (typeof updateValue === "undefined") {
updateValue = !storagedValue updateValue = !storagedValue
@ -71,7 +71,7 @@ const SettingItem = (props) => {
} }
if (item.storaged) { if (item.storaged) {
await window.app.settings.set(item.id, updateValue) await window.app.cores.settings.set(item.id, updateValue)
} }
if (typeof item.emitEvent !== "undefined") { if (typeof item.emitEvent !== "undefined") {
@ -111,7 +111,7 @@ const SettingItem = (props) => {
const checkDependsValidation = () => { const checkDependsValidation = () => {
return !Boolean(Object.keys(item.dependsOn).every((key) => { return !Boolean(Object.keys(item.dependsOn).every((key) => {
const storagedValue = window.app.settings.get(key) const storagedValue = window.app.cores.settings.get(key)
console.debug(`Checking validation for [${key}] with now value [${storagedValue}]`) console.debug(`Checking validation for [${key}] with now value [${storagedValue}]`)
@ -125,7 +125,7 @@ const SettingItem = (props) => {
const settingInitialization = async () => { const settingInitialization = async () => {
if (item.storaged) { if (item.storaged) {
const storagedValue = window.app.settings.get(item.id) const storagedValue = window.app.cores.settings.get(item.id)
setValue(storagedValue) setValue(storagedValue)
} }
@ -243,6 +243,13 @@ const SettingItem = (props) => {
item.props["disabled"] = disabled item.props["disabled"] = disabled
const elementsCtx = {
currentValue: value,
dispatchUpdate,
onUpdateItem,
...props.ctx,
}
return <div key={item.id} className="settingItem"> return <div key={item.id} className="settingItem">
<div className="header"> <div className="header">
<div className="title"> <div className="title">
@ -264,17 +271,27 @@ const SettingItem = (props) => {
{item.extraActions && {item.extraActions &&
<div className="extraActions"> <div className="extraActions">
{item.extraActions.map((action, index) => { {item.extraActions.map((action, index) => {
return <div> if (typeof action === "function") {
<antd.Button return React.createElement(action, {
key={action.id} ctx: elementsCtx,
id={action.id} })
onClick={action.onClick} }
icon={action.icon && createIconRender(action.icon)}
type={action.type ?? "round"} const handleOnClick = () => {
> if (action.onClick) {
{action.title} action.onClick(elementsCtx)
</antd.Button> }
</div> }
return <antd.Button
key={action.id}
id={action.id}
onClick={handleOnClick}
icon={action.icon && createIconRender(action.icon)}
type={action.type ?? "round"}
>
{action.title}
</antd.Button>
})} })}
</div> </div>
} }
@ -286,12 +303,7 @@ const SettingItem = (props) => {
? <div> Loading... </div> ? <div> Loading... </div>
: React.createElement(SettingComponent, { : React.createElement(SettingComponent, {
...item.props, ...item.props,
ctx: { ctx: elementsCtx
currentValue: value,
dispatchUpdate,
onUpdateItem,
...props.ctx,
}
})} })}
</div> </div>

View File

@ -16,6 +16,8 @@
align-items: center; align-items: center;
width: 30%; width: 30%;
padding: 0 30px;
} }
.settings_content { .settings_content {