itd/cmd/itgui/notify.go

41 lines
888 B
Go
Raw Normal View History

2021-08-26 04:18:24 +00:00
package main
import (
2022-05-01 22:22:28 +00:00
"context"
2021-08-26 04:18:24 +00:00
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
2021-10-24 20:27:14 +00:00
"go.arsenm.dev/itd/api"
2021-08-26 04:18:24 +00:00
)
2022-05-05 21:00:49 +00:00
func notifyTab(ctx context.Context, client *api.Client, w fyne.Window) fyne.CanvasObject {
c := container.NewVBox()
c.Add(layout.NewSpacer())
// Create new entry for title
2021-08-26 04:18:24 +00:00
titleEntry := widget.NewEntry()
titleEntry.SetPlaceHolder("Title")
2022-05-05 21:00:49 +00:00
c.Add(titleEntry)
2021-08-26 04:18:24 +00:00
2022-05-05 21:00:49 +00:00
// Create new multiline entry for body
2021-08-26 04:18:24 +00:00
bodyEntry := widget.NewMultiLineEntry()
bodyEntry.SetPlaceHolder("Body")
2022-05-05 21:00:49 +00:00
c.Add(bodyEntry)
2021-08-26 04:18:24 +00:00
2022-05-05 21:00:49 +00:00
// Create new send button
2021-08-26 04:18:24 +00:00
sendBtn := widget.NewButton("Send", func() {
2022-05-05 21:00:49 +00:00
// Send notification
err := client.Notify(ctx, titleEntry.Text, bodyEntry.Text)
2021-08-26 04:18:24 +00:00
if err != nil {
2022-05-05 21:00:49 +00:00
guiErr(err, "Error sending notification", false, w)
2021-08-26 04:18:24 +00:00
return
}
})
2022-05-05 21:00:49 +00:00
c.Add(sendBtn)
2021-08-26 04:18:24 +00:00
2022-05-05 21:00:49 +00:00
c.Add(layout.NewSpacer())
return container.NewVScroll(c)
2021-08-26 04:18:24 +00:00
}