mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 02:24:16 +00:00
rename methods
This commit is contained in:
parent
92d41f4083
commit
710e67c481
@ -6,69 +6,65 @@ import Streaming from "@models/spectrum"
|
||||
import "./index.less"
|
||||
|
||||
const ProfileCreator = (props) => {
|
||||
const [loading, setLoading] = React.useState(false)
|
||||
const [name, setName] = React.useState(props.editValue ?? null)
|
||||
const [loading, setLoading] = React.useState(false)
|
||||
const [name, setName] = React.useState(props.editValue ?? null)
|
||||
|
||||
function handleChange(e) {
|
||||
setName(e.target.value.trim())
|
||||
}
|
||||
function handleChange(e) {
|
||||
setName(e.target.value.trim())
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
setLoading(true)
|
||||
async function handleSubmit() {
|
||||
setLoading(true)
|
||||
|
||||
if (props.editValue) {
|
||||
if (typeof props.onEdit === "function") {
|
||||
await props.onEdit(name)
|
||||
}
|
||||
} else {
|
||||
const result = await Streaming.createOrUpdateStream({ profile_name: name }).catch((error) => {
|
||||
console.error(error)
|
||||
app.message.error("Failed to create")
|
||||
return null
|
||||
})
|
||||
if (props.editValue) {
|
||||
if (typeof props.onEdit === "function") {
|
||||
await props.onEdit(name)
|
||||
}
|
||||
} else {
|
||||
const result = await Streaming.createOrUpdateProfile({
|
||||
profile_name: name,
|
||||
}).catch((error) => {
|
||||
console.error(error)
|
||||
app.message.error("Failed to create")
|
||||
return null
|
||||
})
|
||||
|
||||
if (result) {
|
||||
app.message.success("Created")
|
||||
app.eventBus.emit("app:new_profile", result)
|
||||
props.onCreate(result._id, result)
|
||||
}
|
||||
}
|
||||
if (result) {
|
||||
app.message.success("Created")
|
||||
app.eventBus.emit("app:new_profile", result)
|
||||
props.onCreate(result._id, result)
|
||||
}
|
||||
}
|
||||
|
||||
props.close()
|
||||
props.close()
|
||||
|
||||
setLoading(false)
|
||||
}
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
return <div
|
||||
className="profile-creator"
|
||||
>
|
||||
<antd.Input
|
||||
value={name}
|
||||
placeholder="Enter a profile name"
|
||||
onChange={handleChange}
|
||||
/>
|
||||
return (
|
||||
<div className="profile-creator">
|
||||
<antd.Input
|
||||
value={name}
|
||||
placeholder="Enter a profile name"
|
||||
onChange={handleChange}
|
||||
/>
|
||||
|
||||
<div className="profile-creator-actions">
|
||||
<antd.Button
|
||||
onClick={props.close}
|
||||
>
|
||||
Cancel
|
||||
</antd.Button>
|
||||
<div className="profile-creator-actions">
|
||||
<antd.Button onClick={props.close}>Cancel</antd.Button>
|
||||
|
||||
<antd.Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
handleSubmit(name)
|
||||
}}
|
||||
disabled={!name || loading}
|
||||
loading={loading}
|
||||
>
|
||||
{
|
||||
props.editValue ? "Update" : "Create"
|
||||
}
|
||||
</antd.Button>
|
||||
</div>
|
||||
</div>
|
||||
<antd.Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
handleSubmit(name)
|
||||
}}
|
||||
disabled={!name || loading}
|
||||
loading={loading}
|
||||
>
|
||||
{props.editValue ? "Update" : "Create"}
|
||||
</antd.Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ProfileCreator
|
||||
export default ProfileCreator
|
||||
|
Loading…
x
Reference in New Issue
Block a user