mirror of https://github.com/Nofated095/Q2TG.git
perf: 复用翻页按钮
This commit is contained in:
parent
c6ba18123f
commit
da8b70266f
|
@ -9,24 +9,26 @@ export default async function createPaginatedInlineSelector(chat: TelegramChat,
|
|||
let currentPage = 0;
|
||||
const totalPages = Math.ceil(choices.length / PAGE_SIZE);
|
||||
let sentMessage: Api.Message;
|
||||
const buttonPageUp = Button.inline('⏪ 上一页', chat.parent.registerCallback(() => {
|
||||
currentPage = Math.max(0, currentPage - 1);
|
||||
sentMessage.edit({
|
||||
text: message + `\n\n第 ${currentPage + 1} 页,共 ${totalPages} 页`,
|
||||
buttons: getButtons(),
|
||||
});
|
||||
}));
|
||||
const buttonPageDown = Button.inline('下一页 ⏩', chat.parent.registerCallback(() => {
|
||||
currentPage = Math.min(totalPages - 1, currentPage + 1);
|
||||
console.log(currentPage);
|
||||
sentMessage.edit({
|
||||
text: message + `\n\n第 ${currentPage + 1} 页,共 ${totalPages} 页`,
|
||||
buttons: getButtons(),
|
||||
});
|
||||
}));
|
||||
const getButtons = () => {
|
||||
const buttons = arrays.pagination(choices, PAGE_SIZE, currentPage);
|
||||
const paginateButtons: ButtonLike[] = [];
|
||||
currentPage > 0 && paginateButtons.push(Button.inline('⏪ 上一页', chat.parent.registerCallback(() => {
|
||||
currentPage = Math.max(0, currentPage - 1);
|
||||
sentMessage.edit({
|
||||
text: message + `\n\n第 ${currentPage + 1} 页,共 ${totalPages} 页`,
|
||||
buttons: getButtons(),
|
||||
});
|
||||
})));
|
||||
currentPage !== totalPages - 1 && paginateButtons.push(Button.inline('下一页 ⏩', chat.parent.registerCallback(() => {
|
||||
currentPage = Math.min(totalPages - 1, currentPage + 1);
|
||||
console.log(currentPage);
|
||||
sentMessage.edit({
|
||||
text: message + `\n\n第 ${currentPage + 1} 页,共 ${totalPages} 页`,
|
||||
buttons: getButtons(),
|
||||
});
|
||||
})));
|
||||
currentPage > 0 && paginateButtons.push(buttonPageUp);
|
||||
currentPage !== totalPages - 1 && paginateButtons.push(buttonPageDown);
|
||||
paginateButtons.length && buttons.push(paginateButtons);
|
||||
return buttons;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue