package components import ( "github.com/maxence-charriere/go-app/v9/pkg/app" "github.com/mlctrez/goapp-mdc/pkg/bar" "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" ) type NewChat struct { app.Compo base.JsUtil navigation *Navigation dialog *ModalDialog user *textfield.TextField } func (n *NewChat) Render() app.UI { topBar := &bar.TopAppBar{Title: "Salty IM", Navigation: []app.HTMLButton{icon.MIMenu.Button().OnClick(func(ctx app.Context, e app.Event) { n.navigation.drawer.ActionOpen(ctx) })}, Fixed: true, ScrollTarget: "main-content", Actions: n.topActions(), } if n.user == nil { n.user = &textfield.TextField{Id: "add-user", Label: "Start Chat with user@domain"} n.dialog = &ModalDialog{} n.navigation = &Navigation{} } return app.Div().Body( n.navigation, app.Div().Class("mdc-drawer-app-content").Body( &AppUpdateBanner{}, topBar, app.Div().Class("main-content").ID("main-content").Body( topBar.Main().Body( 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 := saltyim.LookupAddr(n.user.Value) if err != nil { n.dialog.ShowDialog("error", err.Error()) return } 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 }