From c45294e3f5261640749b5b640fe8a0f807827d50 Mon Sep 17 00:00:00 2001 From: MapleLeaf <19603573+itsMapleLeaf@users.noreply.github.com> Date: Mon, 27 Dec 2021 02:32:07 -0600 Subject: [PATCH] make more use of getNextActionRow --- library/core/components/button.tsx | 17 ++--------------- library/core/components/link.tsx | 15 ++------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/library/core/components/button.tsx b/library/core/components/button.tsx index dadf7b4..4e87e3a 100644 --- a/library/core/components/button.tsx +++ b/library/core/components/button.tsx @@ -1,9 +1,9 @@ import { nanoid } from "nanoid" import React from "react" -import { last } from "../../../helpers/last.js" import { ReacordElement } from "../../internal/element.js" import type { ComponentInteraction } from "../../internal/interaction" import type { MessageOptions } from "../../internal/message" +import { getNextActionRow } from "../../internal/message" import { Node } from "../../internal/node.js" export type ButtonProps = { @@ -26,20 +26,7 @@ class ButtonNode extends Node { private customId = nanoid() override modifyMessageOptions(options: MessageOptions): void { - options.actionRows ??= [] - - let actionRow = last(options.actionRows) - - if ( - actionRow == undefined || - actionRow.length >= 5 || - actionRow[0]?.type === "select" - ) { - actionRow = [] - options.actionRows.push(actionRow) - } - - actionRow.push({ + getNextActionRow(options).push({ type: "button", customId: this.customId, style: this.props.style ?? "secondary", diff --git a/library/core/components/link.tsx b/library/core/components/link.tsx index fdbd75e..24f21ab 100644 --- a/library/core/components/link.tsx +++ b/library/core/components/link.tsx @@ -1,7 +1,7 @@ import React from "react" -import { last } from "../../../helpers/last.js" import { ReacordElement } from "../../internal/element.js" import type { MessageOptions } from "../../internal/message" +import { getNextActionRow } from "../../internal/message" import { Node } from "../../internal/node.js" export type LinkProps = { @@ -18,18 +18,7 @@ export function Link(props: LinkProps) { class LinkNode extends Node { override modifyMessageOptions(options: MessageOptions): void { - let actionRow = last(options.actionRows) - - if ( - actionRow == undefined || - actionRow.length >= 5 || - actionRow[0]?.type === "select" - ) { - actionRow = [] - options.actionRows.push(actionRow) - } - - actionRow.push({ + getNextActionRow(options).push({ type: "link", disabled: this.props.disabled, emoji: this.props.emoji,