cleaner flow in select (but there's also a bug oops)
This commit is contained in:
@@ -1,17 +1,15 @@
|
|||||||
import React, { useState } from "react"
|
import React, { useState } from "react"
|
||||||
import { Button, Option, Select } from "../library/main"
|
import { Button, Option, Select } from "../library/main"
|
||||||
|
|
||||||
export function FruitSelect() {
|
export function FruitSelect({
|
||||||
|
onConfirm,
|
||||||
|
}: {
|
||||||
|
onConfirm: (choice: string) => void
|
||||||
|
}) {
|
||||||
const [value, setValue] = useState<string>()
|
const [value, setValue] = useState<string>()
|
||||||
const [finalChoice, setFinalChoice] = useState<string>()
|
|
||||||
|
|
||||||
if (finalChoice) {
|
|
||||||
return <>you chose {finalChoice}</>
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{"_ _"}
|
|
||||||
<Select
|
<Select
|
||||||
placeholder="choose a fruit"
|
placeholder="choose a fruit"
|
||||||
value={value}
|
value={value}
|
||||||
@@ -24,7 +22,9 @@ export function FruitSelect() {
|
|||||||
<Button
|
<Button
|
||||||
label="confirm"
|
label="confirm"
|
||||||
disabled={value == undefined}
|
disabled={value == undefined}
|
||||||
onClick={() => setFinalChoice(value)}
|
onClick={() => {
|
||||||
|
if (value) onConfirm(value)
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -58,7 +58,15 @@ createCommandHandler(client, [
|
|||||||
name: "select",
|
name: "select",
|
||||||
description: "shows a select",
|
description: "shows a select",
|
||||||
run: (interaction) => {
|
run: (interaction) => {
|
||||||
reacord.reply(interaction, <FruitSelect />)
|
const instance = reacord.reply(
|
||||||
|
interaction,
|
||||||
|
<FruitSelect
|
||||||
|
onConfirm={(value) => {
|
||||||
|
instance.render(`you chose ${value}`)
|
||||||
|
instance.deactivate()
|
||||||
|
}}
|
||||||
|
/>,
|
||||||
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user