mirror of
https://git.mills.io/saltyim/saltyim.git
synced 2024-07-08 02:51:32 +00:00
d6fcad992c
Co-authored-by: mlctrez <mlctrez@gmail.com> Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/92 Co-authored-by: mlctrez <mlctrez@noreply@mills.io> Co-committed-by: mlctrez <mlctrez@noreply@mills.io>
81 lines
2.0 KiB
Go
81 lines
2.0 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"
|
|
"go.mills.io/saltyim/internal/pwa/storage"
|
|
)
|
|
|
|
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
|
|
}
|
|
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
|
|
}
|