cleaner flow in select (but there's also a bug oops)

This commit is contained in:
MapleLeaf
2022-01-09 02:11:53 -06:00
parent 954f0cbcac
commit ee239dfc34
2 changed files with 17 additions and 9 deletions

View File

@@ -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)
}}
/> />
</> </>
) )

View File

@@ -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()
}}
/>,
)
}, },
}, },
{ {