* update buttons of reminder for the collect

* add a page arg
This commit is contained in:
Mylloon 2023-01-16 12:04:57 +01:00
parent ffc395b4aa
commit ff8561070a
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 52 additions and 14 deletions

View file

@ -1,12 +1,17 @@
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, Client, Colors, EmbedBuilder } from 'discord.js'; import { ActionRowBuilder, ButtonBuilder, ButtonStyle, Client, Colors, EmbedBuilder, MessageComponentInteraction } from 'discord.js';
import { getFilename } from '../../utils/misc'; import { getFilename } from '../../utils/misc';
export default { export default {
data: { data: {
name: getFilename(__filename), name: getFilename(__filename),
}, },
interaction: async (interaction: ButtonInteraction, client: Client) => { interaction: async (_: MessageComponentInteraction, client: Client) => {
await interaction.deferReply({ ephemeral: true }); // TODO: Dynamically change that
const pageMax = 1;
const page = 1;
// Fetch list
client.db;
const row = new ActionRowBuilder<ButtonBuilder>() const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents( .addComponents(
@ -19,7 +24,7 @@ export default {
.setCustomId('reminderList-next') .setCustomId('reminderList-next')
.setLabel('Next') .setLabel('Next')
.setStyle(ButtonStyle.Primary) .setStyle(ButtonStyle.Primary)
.setDisabled(true), .setDisabled(page === pageMax ? true : false),
); );
@ -28,9 +33,10 @@ export default {
.setTitle('List title') .setTitle('List title')
.setDescription('List desc'); .setDescription('List desc');
return interaction.editReply({ return {
content: 'next',
embeds: [list], embeds: [list],
components: [row], components: [row],
}); };
}, },
}; };

View file

@ -1,12 +1,16 @@
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, Client, Colors, EmbedBuilder } from 'discord.js'; import { ActionRowBuilder, ButtonBuilder, ButtonStyle, Client, Colors, EmbedBuilder, MessageComponentInteraction } from 'discord.js';
import { getFilename } from '../../utils/misc'; import { getFilename } from '../../utils/misc';
export default { export default {
data: { data: {
name: getFilename(__filename), name: getFilename(__filename),
}, },
interaction: async (interaction: ButtonInteraction, client: Client) => { interaction: async (_: MessageComponentInteraction, client: Client) => {
await interaction.deferReply({ ephemeral: true }); // TODO: Dynamically change that
const page = 1;
// Fetch list
client.db;
const row = new ActionRowBuilder<ButtonBuilder>() const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents( .addComponents(
@ -14,7 +18,7 @@ export default {
.setCustomId('reminderList-prec') .setCustomId('reminderList-prec')
.setLabel('Prec') .setLabel('Prec')
.setStyle(ButtonStyle.Primary) .setStyle(ButtonStyle.Primary)
.setDisabled(true)) .setDisabled(page === 1 ? true : false))
.addComponents( .addComponents(
new ButtonBuilder() new ButtonBuilder()
.setCustomId('reminderList-next') .setCustomId('reminderList-next')
@ -28,9 +32,10 @@ export default {
.setTitle('List title') .setTitle('List title')
.setDescription('List desc'); .setDescription('List desc');
return interaction.editReply({ return {
content: 'prec',
embeds: [list], embeds: [list],
components: [row], components: [row],
}); };
}, },
}; };

View file

@ -1,5 +1,6 @@
import { ModalActionRowComponentBuilder, SlashCommandBuilder } from '@discordjs/builders'; import { ModalActionRowComponentBuilder, SlashCommandBuilder } from '@discordjs/builders';
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChatInputCommandInteraction, Client, Colors, EmbedBuilder, ModalBuilder, TextInputBuilder, TextInputStyle } from 'discord.js'; import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChatInputCommandInteraction, Client, Colors, EmbedBuilder, ModalBuilder, TextInputBuilder, TextInputStyle } from 'discord.js';
import { collect } from '../../buttons/loader';
import { getLocale, getLocalizations } from '../../utils/locales'; import { getLocale, getLocalizations } from '../../utils/locales';
import { getFilename } from '../../utils/misc'; import { getFilename } from '../../utils/misc';
import { checkOwnershipReminder, deleteReminder, getReminderInfo, newReminder } from '../../utils/reminder'; import { checkOwnershipReminder, deleteReminder, getReminderInfo, newReminder } from '../../utils/reminder';
@ -102,6 +103,24 @@ export default {
getLocalizations(client, `c_${filename}_sub2_opt1_desc`) getLocalizations(client, `c_${filename}_sub2_opt1_desc`)
) )
) )
// Page
.addIntegerOption(option => option
.setName(
loc_default.get(`c_${filename}_sub2_opt2_name`)
?.toLowerCase() ?? ''
).setDescription(
loc_default.get(`c_${filename}_sub2_opt2_desc`) ?? ''
).setNameLocalizations(
getLocalizations(
client,
`c_${filename}_sub2_opt2_name`,
true
)
).setDescriptionLocalizations(
getLocalizations(client, `c_${filename}_sub2_opt2_desc`)
)
)
) )
// Delete a reminder // Delete a reminder
@ -200,19 +219,25 @@ export default {
user = interaction.user; user = interaction.user;
} }
const idPrec = 'reminderList-prec';
const idNext = 'reminderList-next';
const row = new ActionRowBuilder<ButtonBuilder>() const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents( .addComponents(
new ButtonBuilder() new ButtonBuilder()
.setCustomId('reminderList-prec') .setCustomId(idPrec)
.setLabel('Prec') .setLabel('Prec')
.setStyle(ButtonStyle.Primary) .setStyle(ButtonStyle.Primary)
.setDisabled(true)) .setDisabled(true))
.addComponents( .addComponents(
new ButtonBuilder() new ButtonBuilder()
.setCustomId('reminderList-next') .setCustomId(idNext)
.setLabel('Next') .setLabel('Next')
.setStyle(ButtonStyle.Primary), .setStyle(ButtonStyle.Primary),
); );
// Buttons interactions
collect(client, interaction, idPrec);
collect(client, interaction, idNext);
const list = new EmbedBuilder() const list = new EmbedBuilder()
.setColor(Colors.DarkGrey) .setColor(Colors.DarkGrey)

View file

@ -30,6 +30,8 @@
"c_reminder_sub2_desc": "Affiche la liste des rappels d'un utilisateur", "c_reminder_sub2_desc": "Affiche la liste des rappels d'un utilisateur",
"c_reminder_sub2_opt1_name": "utilisateur", "c_reminder_sub2_opt1_name": "utilisateur",
"c_reminder_sub2_opt1_desc": "Affiche la liste de l'utilisateur en question", "c_reminder_sub2_opt1_desc": "Affiche la liste de l'utilisateur en question",
"c_reminder_sub2_opt2_name": "page",
"c_reminder_sub2_opt2_desc": "Page à afficher",
"c_reminder_sub3_name": "efface", "c_reminder_sub3_name": "efface",
"c_reminder_sub3_desc": "Supprime un rappel", "c_reminder_sub3_desc": "Supprime un rappel",
"c_reminder_sub3_opt1_name": "id", "c_reminder_sub3_opt1_name": "id",