mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +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"
|
import "./index.less"
|
||||||
|
|
||||||
const ProfileCreator = (props) => {
|
const ProfileCreator = (props) => {
|
||||||
const [loading, setLoading] = React.useState(false)
|
const [loading, setLoading] = React.useState(false)
|
||||||
const [name, setName] = React.useState(props.editValue ?? null)
|
const [name, setName] = React.useState(props.editValue ?? null)
|
||||||
|
|
||||||
function handleChange(e) {
|
function handleChange(e) {
|
||||||
setName(e.target.value.trim())
|
setName(e.target.value.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
|
||||||
if (props.editValue) {
|
if (props.editValue) {
|
||||||
if (typeof props.onEdit === "function") {
|
if (typeof props.onEdit === "function") {
|
||||||
await props.onEdit(name)
|
await props.onEdit(name)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const result = await Streaming.createOrUpdateStream({ profile_name: name }).catch((error) => {
|
const result = await Streaming.createOrUpdateProfile({
|
||||||
console.error(error)
|
profile_name: name,
|
||||||
app.message.error("Failed to create")
|
}).catch((error) => {
|
||||||
return null
|
console.error(error)
|
||||||
})
|
app.message.error("Failed to create")
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
app.message.success("Created")
|
app.message.success("Created")
|
||||||
app.eventBus.emit("app:new_profile", result)
|
app.eventBus.emit("app:new_profile", result)
|
||||||
props.onCreate(result._id, result)
|
props.onCreate(result._id, result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
props.close()
|
props.close()
|
||||||
|
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div
|
return (
|
||||||
className="profile-creator"
|
<div className="profile-creator">
|
||||||
>
|
<antd.Input
|
||||||
<antd.Input
|
value={name}
|
||||||
value={name}
|
placeholder="Enter a profile name"
|
||||||
placeholder="Enter a profile name"
|
onChange={handleChange}
|
||||||
onChange={handleChange}
|
/>
|
||||||
/>
|
|
||||||
|
|
||||||
<div className="profile-creator-actions">
|
<div className="profile-creator-actions">
|
||||||
<antd.Button
|
<antd.Button onClick={props.close}>Cancel</antd.Button>
|
||||||
onClick={props.close}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</antd.Button>
|
|
||||||
|
|
||||||
<antd.Button
|
<antd.Button
|
||||||
type="primary"
|
type="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleSubmit(name)
|
handleSubmit(name)
|
||||||
}}
|
}}
|
||||||
disabled={!name || loading}
|
disabled={!name || loading}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
>
|
>
|
||||||
{
|
{props.editValue ? "Update" : "Create"}
|
||||||
props.editValue ? "Update" : "Create"
|
</antd.Button>
|
||||||
}
|
</div>
|
||||||
</antd.Button>
|
</div>
|
||||||
</div>
|
)
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ProfileCreator
|
export default ProfileCreator
|
||||||
|
Loading…
x
Reference in New Issue
Block a user