package components import ( "github.com/maxence-charriere/go-app/v9/pkg/app" "github.com/mlctrez/goapp-mdc/pkg/base" "github.com/mlctrez/goapp-mdc/pkg/button" "github.com/mlctrez/goapp-mdc/pkg/icon" "github.com/mlctrez/goapp-mdc/pkg/textfield" "go.mills.io/saltyim/internal/pwa/storage" "go.mills.io/saltyim/internal/pwa/utils" ) type NewChat struct { app.Compo base.JsUtil dialog *ModalDialog user *textfield.TextField } func (n *NewChat) Render() app.UI { if n.user == nil { n.user = &textfield.TextField{Id: "add-user", Label: "Start Chat with user@domain"} n.dialog = &ModalDialog{} } return PageBody(app.Div().ID("wrapper").Body( app.H4().Text("New Chat"), n.user, &button.Button{Icon: string(icon.MICreate), Label: "New Chat", Outlined: true, Raised: true, Callback: n.newChat()}, n.dialog, ), ) } func (n *NewChat) newChat() func(button app.HTMLButton) { return func(button app.HTMLButton) { button.OnClick(func(ctx app.Context, e app.Event) { addr, err := utils.LookupAddr(n.user.Value) if err != nil { n.dialog.ShowError("error", err.Error()) return } storage.ContactsLocalStorage(ctx).Add(addr.String()) ctx.Navigate("/#" + addr.String()) }) } } func (n *NewChat) topActions() (actions []app.HTMLButton) { actions = append(actions, icon.MIRefresh.Button().Title("reload"). OnClick(func(ctx app.Context, e app.Event) { ctx.Reload() })) return actions }