make more use of getNextActionRow

This commit is contained in:
MapleLeaf
2021-12-27 02:32:07 -06:00
parent ca00131f25
commit c45294e3f5
2 changed files with 4 additions and 28 deletions

View File

@@ -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<ButtonProps> {
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",

View File

@@ -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<LinkProps> {
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,