make more use of getNextActionRow
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { nanoid } from "nanoid"
|
import { nanoid } from "nanoid"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { last } from "../../../helpers/last.js"
|
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../../internal/element.js"
|
||||||
import type { ComponentInteraction } from "../../internal/interaction"
|
import type { ComponentInteraction } from "../../internal/interaction"
|
||||||
import type { MessageOptions } from "../../internal/message"
|
import type { MessageOptions } from "../../internal/message"
|
||||||
|
import { getNextActionRow } from "../../internal/message"
|
||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../../internal/node.js"
|
||||||
|
|
||||||
export type ButtonProps = {
|
export type ButtonProps = {
|
||||||
@@ -26,20 +26,7 @@ class ButtonNode extends Node<ButtonProps> {
|
|||||||
private customId = nanoid()
|
private customId = nanoid()
|
||||||
|
|
||||||
override modifyMessageOptions(options: MessageOptions): void {
|
override modifyMessageOptions(options: MessageOptions): void {
|
||||||
options.actionRows ??= []
|
getNextActionRow(options).push({
|
||||||
|
|
||||||
let actionRow = last(options.actionRows)
|
|
||||||
|
|
||||||
if (
|
|
||||||
actionRow == undefined ||
|
|
||||||
actionRow.length >= 5 ||
|
|
||||||
actionRow[0]?.type === "select"
|
|
||||||
) {
|
|
||||||
actionRow = []
|
|
||||||
options.actionRows.push(actionRow)
|
|
||||||
}
|
|
||||||
|
|
||||||
actionRow.push({
|
|
||||||
type: "button",
|
type: "button",
|
||||||
customId: this.customId,
|
customId: this.customId,
|
||||||
style: this.props.style ?? "secondary",
|
style: this.props.style ?? "secondary",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import { last } from "../../../helpers/last.js"
|
|
||||||
import { ReacordElement } from "../../internal/element.js"
|
import { ReacordElement } from "../../internal/element.js"
|
||||||
import type { MessageOptions } from "../../internal/message"
|
import type { MessageOptions } from "../../internal/message"
|
||||||
|
import { getNextActionRow } from "../../internal/message"
|
||||||
import { Node } from "../../internal/node.js"
|
import { Node } from "../../internal/node.js"
|
||||||
|
|
||||||
export type LinkProps = {
|
export type LinkProps = {
|
||||||
@@ -18,18 +18,7 @@ export function Link(props: LinkProps) {
|
|||||||
|
|
||||||
class LinkNode extends Node<LinkProps> {
|
class LinkNode extends Node<LinkProps> {
|
||||||
override modifyMessageOptions(options: MessageOptions): void {
|
override modifyMessageOptions(options: MessageOptions): void {
|
||||||
let actionRow = last(options.actionRows)
|
getNextActionRow(options).push({
|
||||||
|
|
||||||
if (
|
|
||||||
actionRow == undefined ||
|
|
||||||
actionRow.length >= 5 ||
|
|
||||||
actionRow[0]?.type === "select"
|
|
||||||
) {
|
|
||||||
actionRow = []
|
|
||||||
options.actionRows.push(actionRow)
|
|
||||||
}
|
|
||||||
|
|
||||||
actionRow.push({
|
|
||||||
type: "link",
|
type: "link",
|
||||||
disabled: this.props.disabled,
|
disabled: this.props.disabled,
|
||||||
emoji: this.props.emoji,
|
emoji: this.props.emoji,
|
||||||
|
|||||||
Reference in New Issue
Block a user