Skip to content

Commit

Permalink
fix: Source button sometimes not being shown.
Browse files Browse the repository at this point in the history
  • Loading branch information
vxern committed Dec 14, 2024
1 parent ff3e41f commit b5de7e1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions source/library/commands/components/word-information.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class WordInformationComponent {
}

async #generateButtons(entry: DictionaryEntry): Promise<Discord.MessageComponents> {
const paginationControls: Discord.ButtonComponent[][] = [];
const rows: Discord.ButtonComponent[][] = [];

switch (this.#tab) {
case "overview": {
Expand Down Expand Up @@ -128,7 +128,7 @@ class WordInformationComponent {
localise: this.#client.localise,
locale: this.#anchor.displayLocale,
});
paginationControls.push([
rows.push([
{
type: Discord.MessageComponentTypes.Button,
label: constants.emojis.interactions.menu.controls.back,
Expand Down Expand Up @@ -158,7 +158,7 @@ class WordInformationComponent {
return [];
}

const rows = entry.inflection.tabs.toChunked(5).reverse();
const tabs = entry.inflection.tabs.toChunked(5).reverse();

const button = new InteractionCollector<MenuButtonID>(this.#client, {
only: this.#anchor.parameters.show ? [this.#anchor.user.id] : undefined,
Expand Down Expand Up @@ -189,7 +189,7 @@ class WordInformationComponent {

await this.#client.registerInteractionCollector(button);

for (const [row, rowIndex] of rows.map<[typeof entry.inflection.tabs, number]>((r, i) => [r, i])) {
for (const [row, rowIndex] of tabs.map<[typeof entry.inflection.tabs, number]>((r, i) => [r, i])) {
const buttons = row.map<Discord.ButtonComponent>((table, index) => {
const index_ = rowIndex * 5 + index;

Expand All @@ -203,7 +203,7 @@ class WordInformationComponent {
});

if (buttons.length > 1) {
paginationControls.unshift(buttons);
rows.unshift(buttons);
}
}
}
Expand Down Expand Up @@ -285,11 +285,14 @@ class WordInformationComponent {

row.push(sourceNotice.button);

if (row.length > 1) {
paginationControls.push(row);
const firstRow = rows.at(0);
if (row.length === 1 && firstRow !== undefined && firstRow.length < 5) {
firstRow.push(row.at(0)!);
} else {
rows.push(row);
}

return paginationControls.map((row) => ({
return rows.map((row) => ({
type: Discord.MessageComponentTypes.ActionRow,
components: row as [Discord.ButtonComponent],
}));
Expand Down

0 comments on commit b5de7e1

Please sign in to comment.