Mohammed Foud
commited on
Commit
·
6c1e734
1
Parent(s):
e336b84
all
Browse files
src/bots/utils/keyboardUtils.ts
CHANGED
|
@@ -15,16 +15,23 @@ export const getMainMenuKeyboard = () => {
|
|
| 15 |
]);
|
| 16 |
};
|
| 17 |
|
| 18 |
-
export const getLoggedInMenuKeyboard = () => {
|
| 19 |
const buttons = [];
|
| 20 |
const services = Object.entries(fiveSimProducts);
|
| 21 |
const rowSize = 2; // 2 buttons per row
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
// Generate service buttons in pairs
|
| 24 |
-
for (let i = 0; i <
|
| 25 |
const row = [];
|
| 26 |
-
for (let j = 0; j < rowSize && i + j <
|
| 27 |
-
const [serviceId, serviceData] =
|
| 28 |
row.push(
|
| 29 |
Markup.button.callback(
|
| 30 |
`${serviceData.icon} ${serviceData.label_en}`,
|
|
@@ -35,6 +42,37 @@ export const getLoggedInMenuKeyboard = () => {
|
|
| 35 |
buttons.push(row);
|
| 36 |
}
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
// Add profile and language buttons
|
| 39 |
buttons.push([
|
| 40 |
Markup.button.callback(messageManager.getMessage('btn_profile'), 'profile'),
|
|
|
|
| 15 |
]);
|
| 16 |
};
|
| 17 |
|
| 18 |
+
export const getLoggedInMenuKeyboard = (page: number = 0) => {
|
| 19 |
const buttons = [];
|
| 20 |
const services = Object.entries(fiveSimProducts);
|
| 21 |
const rowSize = 2; // 2 buttons per row
|
| 22 |
+
const servicesPerPage = 10;
|
| 23 |
+
const totalPages = Math.ceil(services.length / servicesPerPage);
|
| 24 |
+
|
| 25 |
+
// Get services for current page
|
| 26 |
+
const startIndex = page * servicesPerPage;
|
| 27 |
+
const endIndex = Math.min(startIndex + servicesPerPage, services.length);
|
| 28 |
+
const pageServices = services.slice(startIndex, endIndex);
|
| 29 |
|
| 30 |
// Generate service buttons in pairs
|
| 31 |
+
for (let i = 0; i < pageServices.length; i += rowSize) {
|
| 32 |
const row = [];
|
| 33 |
+
for (let j = 0; j < rowSize && i + j < pageServices.length; j++) {
|
| 34 |
+
const [serviceId, serviceData] = pageServices[i + j];
|
| 35 |
row.push(
|
| 36 |
Markup.button.callback(
|
| 37 |
`${serviceData.icon} ${serviceData.label_en}`,
|
|
|
|
| 42 |
buttons.push(row);
|
| 43 |
}
|
| 44 |
|
| 45 |
+
// Add pagination buttons
|
| 46 |
+
const paginationRow = [];
|
| 47 |
+
if (page > 0) {
|
| 48 |
+
paginationRow.push(
|
| 49 |
+
Markup.button.callback(
|
| 50 |
+
'⬅️ Previous',
|
| 51 |
+
`services_page_${page - 1}`
|
| 52 |
+
)
|
| 53 |
+
);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
paginationRow.push(
|
| 57 |
+
Markup.button.callback(
|
| 58 |
+
`Page ${page + 1}/${totalPages}`,
|
| 59 |
+
'noop'
|
| 60 |
+
)
|
| 61 |
+
);
|
| 62 |
+
|
| 63 |
+
if (page < totalPages - 1) {
|
| 64 |
+
paginationRow.push(
|
| 65 |
+
Markup.button.callback(
|
| 66 |
+
'Next ➡️',
|
| 67 |
+
`services_page_${page + 1}`
|
| 68 |
+
)
|
| 69 |
+
);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if (paginationRow.length > 0) {
|
| 73 |
+
buttons.push(paginationRow);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
// Add profile and language buttons
|
| 77 |
buttons.push([
|
| 78 |
Markup.button.callback(messageManager.getMessage('btn_profile'), 'profile'),
|