mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
handle prop change
This commit is contained in:
parent
558c2568fd
commit
931d9ecee0
@ -7,55 +7,62 @@ import UploadButton from "@components/UploadButton"
|
|||||||
import "./index.less"
|
import "./index.less"
|
||||||
|
|
||||||
const CoverEditor = (props) => {
|
const CoverEditor = (props) => {
|
||||||
const { value, onChange, defaultUrl } = props
|
const { value, onChange, defaultUrl } = props
|
||||||
|
|
||||||
const [init, setInit] = React.useState(true)
|
const [init, setInit] = React.useState(true)
|
||||||
const [url, setUrl] = React.useState(value)
|
const [url, setUrl] = React.useState(value)
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!init) {
|
if (!init) {
|
||||||
onChange(url)
|
onChange(url)
|
||||||
}
|
}
|
||||||
}, [url])
|
}, [url])
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
setUrl(defaultUrl)
|
setUrl(defaultUrl)
|
||||||
} else {
|
} else {
|
||||||
setUrl(value)
|
setUrl(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
setInit(false)
|
setInit(false)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return <div className="cover-editor">
|
// Handle when value prop change
|
||||||
<div className="cover-editor-preview">
|
React.useEffect(() => {
|
||||||
<Image
|
if (!value) {
|
||||||
src={url}
|
setUrl(defaultUrl)
|
||||||
/>
|
} else {
|
||||||
</div>
|
setUrl(value)
|
||||||
|
}
|
||||||
|
}, [value])
|
||||||
|
|
||||||
<div className="cover-editor-actions">
|
return (
|
||||||
<UploadButton
|
<div className="cover-editor">
|
||||||
onSuccess={(uid, response) => {
|
<div className="cover-editor-preview">
|
||||||
setUrl(response.url)
|
<Image src={url} />
|
||||||
}}
|
</div>
|
||||||
/>
|
|
||||||
|
|
||||||
<antd.Button
|
<div className="cover-editor-actions">
|
||||||
type="primary"
|
<UploadButton
|
||||||
onClick={() => {
|
onSuccess={(uid, response) => {
|
||||||
setUrl(defaultUrl)
|
setUrl(response.url)
|
||||||
}}
|
}}
|
||||||
>
|
/>
|
||||||
Reset
|
|
||||||
</antd.Button>
|
|
||||||
|
|
||||||
{
|
<antd.Button
|
||||||
props.extraActions
|
type="primary"
|
||||||
}
|
onClick={() => {
|
||||||
</div>
|
setUrl(defaultUrl)
|
||||||
</div>
|
}}
|
||||||
|
>
|
||||||
|
Reset
|
||||||
|
</antd.Button>
|
||||||
|
|
||||||
|
{props.extraActions}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CoverEditor
|
export default CoverEditor
|
||||||
|
@ -10,13 +10,13 @@ export default async ({ username, password, hash }, user) => {
|
|||||||
user = await User.findOne(query).select("+email").select("+password")
|
user = await User.findOne(query).select("+email").select("+password")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new OperationError(401, "User not found")
|
throw new OperationError(401, "User not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.disabled == true) {
|
if (user.disabled == true) {
|
||||||
throw new OperationError(401, "User is disabled")
|
throw new OperationError(401, "User is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof hash !== "undefined") {
|
if (typeof hash !== "undefined") {
|
||||||
if (user.password !== hash) {
|
if (user.password !== hash) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user