6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-07-08 02:51:32 +00:00
prologic-saltyim/internal/pwa/components/newchat.go
mlctrez 969a263d06 support for contacts, multiple chat threads, and persistence (#77)
Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Co-authored-by: James Mills <james@mills.io>
Co-authored-by: mlctrez <mlctrez@gmail.com>
Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/77
Co-authored-by: mlctrez <mlctrez@noreply@mills.io>
Co-committed-by: mlctrez <mlctrez@noreply@mills.io>
2022-03-28 21:49:01 +00:00

79 lines
1.9 KiB
Go

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
}