Skip to content

Commit

Permalink
perf(pagination): better response time
Browse files Browse the repository at this point in the history
  • Loading branch information
virtual-designer committed Oct 11, 2022
1 parent faa166d commit 9feec27
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/utils/Pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface PaginationOptions<T> {
guild_id: string;
channel_id: string;
user_id?: string;
timeout?: number;
embedBuilder: (options: EmbedBuilderOptions<T>) => MessageEmbed;
actionRowBuilder?: (options: { first: boolean, last: boolean, next: boolean, back: boolean }) => MessageActionRow<MessageButton>;
}
Expand Down Expand Up @@ -60,7 +61,7 @@ export default class Pagination<T> {

options.embeds ??= [];
options.embeds.push(this.getEmbed(page));
console.log(options.embeds);

options.components ??= [];
options.components.push(this.getActionRow(actionRowOptionsDup));

Expand All @@ -72,7 +73,7 @@ export default class Pagination<T> {
return this.options.actionRowBuilder({ first, last, next, back });
}

const actionRow = new MessageActionRow<MessageButton>;
const actionRow = new MessageActionRow<MessageButton>();

actionRow.addComponents(
new MessageButton()
Expand Down Expand Up @@ -107,7 +108,7 @@ export default class Pagination<T> {
interactionType: 'MESSAGE_COMPONENT',
componentType: 'BUTTON',
message,
time: 60_000,
time: this.options.timeout ?? 60_000,
filter: interaction => {
if (interaction.inGuild() && (!this.options.user_id || interaction.user.id === this.options.user_id)) {
return true;
Expand All @@ -126,6 +127,8 @@ export default class Pagination<T> {
return;
}

// await interaction.deferUpdate();

const maxPage = Math.ceil(this.data.length / this.options.limit);
const componentOptions = { first: true, last: true, next: true, back: true };

Expand Down Expand Up @@ -162,7 +165,13 @@ export default class Pagination<T> {
});

collector.on("end", async () => {
await message.edit({ components: [this.getActionRow({ first: false, last: false, next: false, back: false })] });
const component = message.components[0]; // this.getActionRow({ first: false, last: false, next: false, back: false })

for (const i in component.components) {
component.components[i].disabled = true;
}

await message.edit({ components: [component] });
});
}
}

0 comments on commit 9feec27

Please sign in to comment.