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,