add year navigation: year row at top of calendar, clickable year in export, shared buildYearPicker with 12-year grid
This commit is contained in:
@@ -377,7 +377,7 @@ func (h *Handler) editExportMonthPicker(ctx context.Context, chatID int64, msgID
|
||||
// Year navigation
|
||||
{
|
||||
{Text: "<", CallbackData: fmt.Sprintf("exp_year_prev_%d", year)},
|
||||
{Text: fmt.Sprintf("%d", year), CallbackData: "noop"},
|
||||
{Text: fmt.Sprintf("%d", year), CallbackData: fmt.Sprintf("exp_show_years_%d", year)},
|
||||
{Text: ">", CallbackData: fmt.Sprintf("exp_year_next_%d", year)},
|
||||
},
|
||||
}
|
||||
@@ -405,6 +405,17 @@ func (h *Handler) editExportMonthPicker(ctx context.Context, chatID int64, msgID
|
||||
}
|
||||
}
|
||||
|
||||
// editExportYearPicker shows a 12-year grid for year selection in the export flow.
|
||||
// refY is the year to return to via the Back button.
|
||||
func (h *Handler) editExportYearPicker(ctx context.Context, chatID int64, msgID int, centerYear, refY int) {
|
||||
backData := fmt.Sprintf("exp_years_back_%d", refY)
|
||||
navSuffix := fmt.Sprintf("_%d", refY)
|
||||
kb := buildYearPicker("exp_", backData, navSuffix, centerYear)
|
||||
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
|
||||
ChatID: chatID, MessageID: msgID, Text: "Select year:", ReplyMarkup: &kb,
|
||||
})
|
||||
}
|
||||
|
||||
// formatMonthTitle returns the localized month name and year for a given calendar.
|
||||
func formatMonthTitle(cal string, year, month int) string {
|
||||
switch cal {
|
||||
@@ -437,6 +448,27 @@ func (h *Handler) handleExportCallback(ctx context.Context, chatID int64, msgID
|
||||
h.editExportMonthPicker(ctx, chatID, msgID, y+1, 0, user)
|
||||
return
|
||||
}
|
||||
// Show year picker from month picker
|
||||
if n, _ := fmt.Sscanf(data, "exp_show_years_%d", &y); n == 1 {
|
||||
h.editExportYearPicker(ctx, chatID, msgID, y, y)
|
||||
return
|
||||
}
|
||||
// Navigate year block in picker
|
||||
var refY int
|
||||
if n, _ := fmt.Sscanf(data, "exp_years_%d_%d", &y, &refY); n == 2 {
|
||||
h.editExportYearPicker(ctx, chatID, msgID, y+6, refY)
|
||||
return
|
||||
}
|
||||
// Select year from picker
|
||||
if n, _ := fmt.Sscanf(data, "exp_year_%d", &y); n == 1 {
|
||||
h.editExportMonthPicker(ctx, chatID, msgID, y, 0, user)
|
||||
return
|
||||
}
|
||||
// Back from year picker to month picker
|
||||
if n, _ := fmt.Sscanf(data, "exp_years_back_%d", &y); n == 1 {
|
||||
h.editExportMonthPicker(ctx, chatID, msgID, y, 0, user)
|
||||
return
|
||||
}
|
||||
|
||||
// Export a specific month
|
||||
if n, _ := fmt.Sscanf(data, "exp_do_%d_%d", &y, &m); n == 2 {
|
||||
|
||||
Reference in New Issue
Block a user