Added MyTitles page passing
This commit is contained in:
parent
45ce5da0ac
commit
45a1df4cbb
8 changed files with 110 additions and 1 deletions
|
|
@ -13,3 +13,46 @@ TgBot::InlineKeyboardMarkup::Ptr KeyboardFactory::createMainMenu() {
|
|||
keyboard->inlineKeyboard = {{button1, button2}};
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
TgBot::InlineKeyboardMarkup::Ptr KeyboardFactory::createMyTitles(std::vector<Title> titles) {
|
||||
auto keyboard = std::make_shared<TgBot::InlineKeyboardMarkup>();
|
||||
std::vector<TgBot::InlineKeyboardButton::Ptr> row;
|
||||
std::vector<std::vector<TgBot::InlineKeyboardButton::Ptr>> layout;
|
||||
|
||||
int counter = 0;
|
||||
for(Title& title : titles) {
|
||||
if(counter >= 6) {
|
||||
break;
|
||||
}
|
||||
auto button = std::make_shared<TgBot::InlineKeyboardButton>();
|
||||
button->text = std::to_string(title.num) + " " + title.name;
|
||||
button->callbackData = "title:" + std::to_string(title.num);
|
||||
row.push_back(button);
|
||||
counter++;
|
||||
if(counter % 2 == 0) {
|
||||
layout.push_back(row);
|
||||
row.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Додумать логику, когда пришло 6 записей в конце
|
||||
if(counter % 2 == 1) {
|
||||
auto button = std::make_shared<TgBot::InlineKeyboardButton>();
|
||||
button->text = BotConstants::Button::PREV;
|
||||
button->callbackData = BotConstants::Callback::LIST_PREV + std::to_string(titles[0].num);
|
||||
layout[counter / 2].push_back(button);
|
||||
}
|
||||
else {
|
||||
auto button_prev = std::make_shared<TgBot::InlineKeyboardButton>();
|
||||
button_prev->text = BotConstants::Button::PREV;
|
||||
button_prev->callbackData = BotConstants::Callback::LIST_PREV + std::to_string(titles[0].num);
|
||||
auto button_next = std::make_shared<TgBot::InlineKeyboardButton>();
|
||||
button_next->text = BotConstants::Button::NEXT;
|
||||
button_next->callbackData = BotConstants::Callback::LIST_NEXT + std::to_string(titles[5].num);
|
||||
layout.push_back({button_prev, button_next});
|
||||
}
|
||||
|
||||
keyboard->inlineKeyboard = layout;
|
||||
|
||||
return keyboard;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue