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 { Button, Option, Select } from "../library/main"
export function FruitSelect() {
export function FruitSelect({
onConfirm,
}: {
onConfirm: (choice: string) => void
}) {
const [value, setValue] = useState<string>()
const [finalChoice, setFinalChoice] = useState<string>()
if (finalChoice) {
return <>you chose {finalChoice}</>
}
return (
<>
{"_ _"}
<Select
placeholder="choose a fruit"
value={value}
@@ -24,7 +22,9 @@ export function FruitSelect() {
<Button
label="confirm"
disabled={value == undefined}
onClick={() => setFinalChoice(value)}
onClick={() => {
if (value) onConfirm(value)
}}
/>
</>
)

View File

@@ -58,7 +58,15 @@ createCommandHandler(client, [
name: "select",
description: "shows a select",
run: (interaction) => {
reacord.reply(interaction, <FruitSelect />)
const instance = reacord.reply(
interaction,
<FruitSelect
onConfirm={(value) => {
instance.render(`you chose ${value}`)
instance.deactivate()
}}
/>,
)
},
},
{