fix: adjust file pagination limit and improve embed formatting
This commit is contained in:
parent
0fda50dfb5
commit
9583267f64
1 changed files with 7 additions and 2 deletions
|
@ -16,11 +16,12 @@ export const data = new SlashCommandBuilder()
|
||||||
);
|
);
|
||||||
|
|
||||||
export async function renderList(user: User, userId: string, page: number): Promise<InteractionReplyOptions> {
|
export async function renderList(user: User, userId: string, page: number): Promise<InteractionReplyOptions> {
|
||||||
const amount = 4;
|
const amount = 3;
|
||||||
|
|
||||||
const { count } = await db.get<{ count: number }>`
|
const { count } = await db.get<{ count: number }>`
|
||||||
SELECT COUNT(*) as count FROM files WHERE owner = ${userId}
|
SELECT COUNT(*) as count FROM files WHERE owner = ${userId}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const totalPages = Math.max(1, Math.ceil(count / amount));
|
const totalPages = Math.max(1, Math.ceil(count / amount));
|
||||||
const pages = Math.max(1, Math.min(page, totalPages));
|
const pages = Math.max(1, Math.min(page, totalPages));
|
||||||
|
|
||||||
|
@ -37,12 +38,16 @@ export async function renderList(user: User, userId: string, page: number): Prom
|
||||||
const embed = createEmbed(user)
|
const embed = createEmbed(user)
|
||||||
.setTitle("your files")
|
.setTitle("your files")
|
||||||
.addFields(...files.map(file => ({
|
.addFields(...files.map(file => ({
|
||||||
name: file.name,
|
name: `\`${file.name}\``,
|
||||||
value: `${formatSize(file.size)}\n${new Date(file.created_at).toLocaleString()}\n[open in browser](${process.env.API}/${file.id})`,
|
value: `${formatSize(file.size)}\n${new Date(file.created_at).toLocaleString()}\n[open in browser](${process.env.API}/${file.id})`,
|
||||||
inline: true
|
inline: true
|
||||||
})))
|
})))
|
||||||
.setFooter({ text: `page ${pages} of ${totalPages}` });
|
.setFooter({ text: `page ${pages} of ${totalPages}` });
|
||||||
|
|
||||||
|
if (totalPages <= 1) {
|
||||||
|
return { embeds: [embed] }
|
||||||
|
}
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||||
.addComponents(
|
.addComponents(
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue