MobileMkch/ui/create_thread_screen.go

108 lines
3.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ui
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
type CreateThreadScreen struct {
uiManager *UIManager
content *fyne.Container
boardCode string
}
func NewCreateThreadScreen(uiManager *UIManager, boardCode string) *CreateThreadScreen {
cts := &CreateThreadScreen{
uiManager: uiManager,
boardCode: boardCode,
content: container.NewVBox(),
}
cts.setupContent()
return cts
}
func (cts *CreateThreadScreen) setupContent() {
cts.content.Objects = nil
titleLabel := widget.NewLabel(fmt.Sprintf("Создать тред в /%s/", cts.boardCode))
titleLabel.TextStyle = fyne.TextStyle{Bold: true}
cts.content.Add(titleLabel)
titleEntry := widget.NewEntry()
titleEntry.SetPlaceHolder("Заголовок треда")
cts.content.Add(titleEntry)
textEntry := widget.NewMultiLineEntry()
textEntry.SetPlaceHolder("Текст треда")
textEntry.Resize(fyne.NewSize(300, 200))
cts.content.Add(textEntry)
passcode := cts.uiManager.GetPasscode()
if passcode != "" {
passcodeLabel := widget.NewLabel("Passcode настроен ✓")
passcodeLabel.TextStyle = fyne.TextStyle{Bold: true}
cts.content.Add(passcodeLabel)
} else {
passcodeLabel := widget.NewLabel("Passcode не настроен - постинг может быть ограничен\nи могут быть неожиданные ПРОБЛЕЕМЫ\n(подробнее в настройках)")
passcodeLabel.TextStyle = fyne.TextStyle{Bold: true}
cts.content.Add(passcodeLabel)
}
buttonsContainer := container.NewHBox()
createButton := widget.NewButton("Создать тред", func() {
title := titleEntry.Text
text := textEntry.Text
if title == "" {
cts.uiManager.ShowError("Ошибка", "Заголовок не может быть пустым")
return
}
if text == "" {
cts.uiManager.ShowError("Ошибка", "Текст не может быть пустым")
return
}
cts.uiManager.ShowInfo("Создание треда", "Отправляем тред...")
passcode := cts.uiManager.GetPasscode()
err := cts.uiManager.GetAPIClient().CreateThread(cts.boardCode, title, text, passcode)
if err != nil {
cts.uiManager.ShowError("Ошибка", fmt.Sprintf("Не удалось создать тред: %v", err))
return
}
cts.uiManager.ClearCacheForBoard(cts.boardCode)
cts.uiManager.ShowInfo("Успех", "Тред создан успешно!")
cts.uiManager.GoBack()
cts.uiManager.RefreshCurrentScreen()
})
cancelButton := widget.NewButton("Отмена", func() {
cts.uiManager.GoBack()
})
buttonsContainer.Add(createButton)
buttonsContainer.Add(cancelButton)
cts.content.Add(buttonsContainer)
cts.content.Refresh()
}
func (cts *CreateThreadScreen) GetContent() fyne.CanvasObject {
return cts.content
}
func (cts *CreateThreadScreen) GetTitle() string {
return fmt.Sprintf("Создать тред /%s/", cts.boardCode)
}
func (cts *CreateThreadScreen) OnShow() {
cts.setupContent()
}
func (cts *CreateThreadScreen) OnHide() {
// Ничего не делаем при скрытии
}