refactor + fix добавление проекта

This commit is contained in:
Artem Tsyrulnikov
2026-01-20 15:16:06 +03:00
parent 7f6527652b
commit 4e4f9810d9
10 changed files with 251 additions and 235 deletions

View File

@@ -173,3 +173,47 @@ func BuildElementRows(config ElementLayoutConfig, allItems []echotron.InlineKeyb
return rows
}
// BuildPageRows раскладывает элементы текущей страницы без собственной пагинации.
// Автоматически заполняет пустыми кнопками если страниц > 1 (для консистентности высоты).
func BuildPageRows(pageItems []echotron.InlineKeyboardButton, itemsPerRow, itemsPerPage, totalPages int) [][]echotron.InlineKeyboardButton {
if len(pageItems) == 0 {
return nil
}
// Параметры по умолчанию
if itemsPerPage <= 0 {
itemsPerPage = 6
}
if itemsPerRow <= 0 {
itemsPerRow = 2
}
// Кнопка-заполнитель по умолчанию
emptyButton := echotron.InlineKeyboardButton{Text: " ", CallbackData: "empty"}
// Если страниц >= 2, заполняем до ItemsPerPage пустыми кнопками
if totalPages >= 2 {
for len(pageItems) < itemsPerPage {
pageItems = append(pageItems, emptyButton)
}
}
// Раскладываем элементы по рядам
var rows [][]echotron.InlineKeyboardButton
for i := 0; i < len(pageItems); i += itemsPerRow {
var row []echotron.InlineKeyboardButton
for j := 0; j < itemsPerRow && i+j < len(pageItems); j++ {
row = append(row, pageItems[i+j])
}
for len(row) < itemsPerRow {
row = append(row, emptyButton)
}
rows = append(rows, row)
}
return rows
}