From 37c913060a9cee103dc774d884084a8b4b6a7ef4 Mon Sep 17 00:00:00 2001 From: Helloyunho Date: Fri, 1 Mar 2024 02:34:53 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=EF=B8=8F=20fix:=20new=20typescript?= =?UTF-8?q?=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interactions/tsxComponents.ts | 52 +++++++++++++++++-------------- src/types/messageComponents.ts | 2 +- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/interactions/tsxComponents.ts b/src/interactions/tsxComponents.ts index a48f5fa4..6b0ffaf7 100644 --- a/src/interactions/tsxComponents.ts +++ b/src/interactions/tsxComponents.ts @@ -60,6 +60,7 @@ export interface SelectProps { placeholder?: string minValues?: number maxValues?: number + disabled?: boolean } /** Select (drop down) component. Allows user to choose one or more options */ @@ -149,31 +150,36 @@ export function fragment( component.children ?.flat(2) - .forEach((el: Element) => { - if (el.type !== 'Button' && el.type !== 'Select') { + .forEach((el: Element) => { + if (el.type === 'Button') { + const props = el.props as ButtonProps + row.components?.push({ + type: 2, + custom_id: props.id, + label: props.label, + style: resolveStyle(props.style), + url: props.url, + emoji: props.emoji, + disabled: props.disabled + }) + } else if (el.type === 'Select') { + const props = el.props as SelectProps + row.components?.push({ + type: 3, + custom_id: props.id, + min_values: props.minValues, + max_values: props.maxValues, + placeholder: props.placeholder, + disabled: props.disabled, + options: Array.isArray(el.children) + ? el.children.map((e) => { + return e.props + }) + : [] + }) + } else { throw new Error('Invalid second level component: ' + el.type) } - - row.components?.push({ - type: el.type === 'Button' ? 2 : 3, - custom_id: el.props.id, - label: el.props.label, - style: - el.props.style !== undefined - ? resolveStyle(el.props.style) - : undefined, - url: el.props.url, - emoji: el.props.emoji, - min_values: el.props.minValues, - max_values: el.props.maxValues, - placeholder: el.props.placeholder, - disabled: el.props.disabled, - options: Array.isArray(el.children) - ? el.children.map((e) => { - return e.props - }) - : [] - }) }) if (row.components !== undefined && row.components.length > 5) { diff --git a/src/types/messageComponents.ts b/src/types/messageComponents.ts index 290da06b..178339f8 100644 --- a/src/types/messageComponents.ts +++ b/src/types/messageComponents.ts @@ -56,7 +56,7 @@ export interface ActionRowComponent { export interface ButtonComponentPayload { type: MessageComponentType.BUTTON - label: string + label?: string style: ButtonStyle custom_id?: string url?: string