фиксы
This commit is contained in:
@@ -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"),
|
||||
))
|
||||
|
||||
// Кнопка тега
|
||||
|
||||
Reference in New Issue
Block a user