фиксы
This commit is contained in:
@@ -94,12 +94,12 @@ func (s *CreativeDetails) HandleCallback(b *bot.Bot, u *echotron.Update) {
|
||||
// Обрабатываем общие callbacks (edit_text, add_button, add_media, delete_button, delete_media)
|
||||
switch {
|
||||
case data == "cancel", data == "back":
|
||||
// Отмена - возвращаемся назад
|
||||
// Удаляем сообщения текущего экрана перед переходом
|
||||
s.CleanupMessages(b)
|
||||
if s.ViewMode && s.ViewBackTo != nil {
|
||||
// Если открыты из view mode, возвращаемся к просмотру
|
||||
b.SetState(s.ViewBackTo, bot.EditMessage)
|
||||
b.SetState(s.ViewBackTo, bot.NewMessage)
|
||||
} else if s.BackState != nil {
|
||||
b.SetState(s.BackState, bot.EditMessage)
|
||||
b.SetState(s.BackState, bot.NewMessage)
|
||||
}
|
||||
|
||||
case data == "edit_text":
|
||||
|
||||
@@ -136,6 +136,18 @@ func (e *CreativeEditorFields) clearExtraMediaMessages(b *bot.Bot) {
|
||||
e.ExtraMediaMessageIDs = nil
|
||||
}
|
||||
|
||||
func (e *CreativeEditorFields) CleanupMessages(b *bot.Bot) {
|
||||
if e.CreativeMessageID != nil {
|
||||
b.DeleteMessage(b.ChatID, *e.CreativeMessageID)
|
||||
e.CreativeMessageID = nil
|
||||
}
|
||||
e.clearExtraMediaMessages(b)
|
||||
if e.ControlPanelMessageID != nil {
|
||||
b.DeleteMessage(b.ChatID, *e.ControlPanelMessageID)
|
||||
e.ControlPanelMessageID = nil
|
||||
}
|
||||
}
|
||||
|
||||
const mediaGroupDebounce = 2 * time.Second
|
||||
|
||||
func (e *CreativeEditorFields) scheduleMediaGroupAction(groupID string, action func()) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package screens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/NicoNex/echotron/v3"
|
||||
"github.com/TelegramExchange/tgex-backend/tg_bot/backend"
|
||||
@@ -24,6 +25,8 @@ type CreativeView struct {
|
||||
ProjectStatus string
|
||||
|
||||
BackState bot.State
|
||||
|
||||
renaming bool // режим ввода нового названия
|
||||
}
|
||||
|
||||
const msgCreativeView = `
|
||||
@@ -33,6 +36,10 @@ const msgCreativeView = `
|
||||
`
|
||||
|
||||
func (s *CreativeView) Enter(b *bot.Bot, mode bot.RenderMode) {
|
||||
// Сбрасываем старые ID — при re-enter всегда создаём свежие сообщения
|
||||
s.CreativeMessageID = nil
|
||||
s.ControlPanelMessageID = nil
|
||||
|
||||
// Загружаем креатив
|
||||
creative, err := b.Backend.GetCreative(context.Background(), b.Session.JWT, b.Session.WorkspaceID, s.CreativeID)
|
||||
if err != nil {
|
||||
@@ -98,6 +105,16 @@ func (s *CreativeView) HandleCallback(b *bot.Bot, u *echotron.Update) {
|
||||
b.SetState(s.BackState, bot.EditMessage)
|
||||
}
|
||||
|
||||
case data == "rename":
|
||||
s.renaming = true
|
||||
s.ShowControlPanel(b, "<b>✏️ Введите новое название креатива:</b>", [][]echotron.InlineKeyboardButton{
|
||||
Row(Button("← Отмена", "cancel_rename")),
|
||||
})
|
||||
|
||||
case data == "cancel_rename":
|
||||
s.renaming = false
|
||||
s.showActionPanel(b)
|
||||
|
||||
case data == "edit":
|
||||
// Переход к редактированию креатива
|
||||
b.SetState(&CreativeDetails{
|
||||
@@ -136,7 +153,32 @@ func (s *CreativeView) HandleCallback(b *bot.Bot, u *echotron.Update) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CreativeView) HandleMessage(_ *bot.Bot, _ *echotron.Update) {}
|
||||
func (s *CreativeView) HandleMessage(b *bot.Bot, u *echotron.Update) {
|
||||
if !s.renaming || u.Message == nil || u.Message.Text == "" {
|
||||
return
|
||||
}
|
||||
|
||||
newName := strings.TrimSpace(u.Message.Text)
|
||||
s.DeleteUserMessage(b, u.Message.ID)
|
||||
|
||||
input := backend.UpdateCreativeInput{
|
||||
Name: &newName,
|
||||
}
|
||||
_, err := b.Backend.UpdateCreative(
|
||||
context.Background(), b.Session.JWT, b.Session.WorkspaceID, s.CreativeID, input,
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("creative_id", s.CreativeID).Msg("Failed to rename creative")
|
||||
s.ShowControlPanel(b, "<b>❌ Не удалось переименовать</b>", [][]echotron.InlineKeyboardButton{
|
||||
Row(Button("← Назад", "cancel_rename")),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
s.Name = &newName
|
||||
s.renaming = false
|
||||
s.showActionPanel(b)
|
||||
}
|
||||
|
||||
func (s *CreativeView) Handle(_ *bot.Bot, _ *echotron.Update) { return }
|
||||
|
||||
@@ -150,9 +192,14 @@ func (s *CreativeView) showActionPanel(b *bot.Bot) {
|
||||
// Если креатив архивирован (в будущем), можно изменить кнопки
|
||||
var buttons [][]echotron.InlineKeyboardButton
|
||||
|
||||
// Кнопка переименования
|
||||
buttons = append(buttons, Row(
|
||||
Button("✏️ Переименовать", "rename"),
|
||||
))
|
||||
|
||||
// Кнопка редактирования
|
||||
buttons = append(buttons, Row(
|
||||
Button("✏️ Редактировать", "edit"),
|
||||
Button("🖊 Редактировать", "edit"),
|
||||
))
|
||||
|
||||
// Кнопка тега
|
||||
|
||||
@@ -926,7 +926,7 @@ func (s *PurchaseOptionalDetails) renderCustomFormatTop(b *bot.Bot, mode bot.Ren
|
||||
Button("90", "format_custom_top:90"),
|
||||
Button("120", "format_custom_top:120"),
|
||||
),
|
||||
Row(Button("⏱ В часах", "format_custom_top_toggle_unit")),
|
||||
Row(Button("⏱ Минуты", "format_custom_top_toggle_unit")),
|
||||
)
|
||||
} else {
|
||||
text += "Выберите или введите число (в часах):"
|
||||
@@ -943,7 +943,7 @@ func (s *PurchaseOptionalDetails) renderCustomFormatTop(b *bot.Bot, mode bot.Ren
|
||||
Button("8", "format_custom_top:480"),
|
||||
Button("12", "format_custom_top:720"),
|
||||
),
|
||||
Row(Button("⏱ В минутах", "format_custom_top_toggle_unit")),
|
||||
Row(Button("⏱ Часы", "format_custom_top_toggle_unit")),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -980,7 +980,7 @@ func (s *PurchaseOptionalDetails) renderCustomFormatFeed(b *bot.Bot, mode bot.Re
|
||||
Button("365", "format_custom_feed:525600"),
|
||||
),
|
||||
Row(
|
||||
Button("⏱ В часах", "format_custom_feed_toggle_unit"),
|
||||
Button("⏱ Дни", "format_custom_feed_toggle_unit"),
|
||||
Button("Без удаления", "format_custom_feed:0"),
|
||||
),
|
||||
)
|
||||
@@ -1000,7 +1000,7 @@ func (s *PurchaseOptionalDetails) renderCustomFormatFeed(b *bot.Bot, mode bot.Re
|
||||
Button("168", "format_custom_feed:10080"),
|
||||
),
|
||||
Row(
|
||||
Button("⏱ В днях", "format_custom_feed_toggle_unit"),
|
||||
Button("⏱ Часы", "format_custom_feed_toggle_unit"),
|
||||
Button("Без удаления", "format_custom_feed:0"),
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user