fix ctx for settings items

This commit is contained in:
SrGooglo 2023-07-27 00:02:48 +00:00
parent bec5a2b5d0
commit d02bd49231
3 changed files with 17 additions and 5 deletions

View File

@ -7,6 +7,10 @@ import "./index.less"
export default (props) => { export default (props) => {
const [value, setValue] = React.useState(props.ctx.currentValue) const [value, setValue] = React.useState(props.ctx.currentValue)
React.useEffect(() => {
setValue(props.ctx.currentValue)
}, [props.ctx.currentValue])
return <div className="imageUploader"> return <div className="imageUploader">
{ {
!props.noPreview && value && <div className="uploadPreview"> !props.noPreview && value && <div className="uploadPreview">

View File

@ -1,4 +1,3 @@
import React from "react"
import UserModel from "models/user" import UserModel from "models/user"
import loadable from "@loadable/component" import loadable from "@loadable/component"
import UploadButton from "components/UploadButton" import UploadButton from "components/UploadButton"
@ -105,7 +104,6 @@ export default {
UploadButton UploadButton
], ],
"defaultValue": (ctx) => { "defaultValue": (ctx) => {
console.log(ctx)
return ctx.userData.avatar return ctx.userData.avatar
}, },
"onUpdate": async (value) => { "onUpdate": async (value) => {
@ -118,7 +116,6 @@ export default {
return value return value
} }
}, },
"debounced": true,
}, },
{ {
"id": "cover", "id": "cover",
@ -143,7 +140,6 @@ export default {
return value return value
} }
}, },
"debounced": true,
}, },
{ {
"id": "description", "id": "description",

View File

@ -419,6 +419,7 @@ export default class SettingItemComponent extends React.PureComponent {
currentValue: this.state.value, currentValue: this.state.value,
dispatchUpdate: this.dispatchUpdate, dispatchUpdate: this.dispatchUpdate,
onUpdateItem: this.onUpdateItem, onUpdateItem: this.onUpdateItem,
processedCtx: this.props.ctx,
}, },
ref: this.componentRef, ref: this.componentRef,
@ -469,7 +470,18 @@ export default class SettingItemComponent extends React.PureComponent {
{ {
this.props.setting.extraActions.map((action, index) => { this.props.setting.extraActions.map((action, index) => {
if (typeof action === "function") { if (typeof action === "function") {
return React.createElement(action) return React.createElement(action, {
ctx: {
updateCurrentValue: (updateValue) => this.setState({
value: updateValue
}),
getCurrentValue: () => this.state.value,
currentValue: this.state.value,
dispatchUpdate: this.dispatchUpdate,
onUpdateItem: this.onUpdateItem,
processedCtx: this.props.ctx
},
})
} }
const handleOnClick = () => { const handleOnClick = () => {