6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-07-03 00:33:38 +00:00
prologic-saltyim/internal/pwa/components/newchat.go
mlctrez fcc4f53f20 navigation drawer is now fixed for > 900px windows (#157)
Co-authored-by: mlctrez <mlctrez@gmail.com>
Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/157
Reviewed-by: James Mills <james@mills.io>
Co-authored-by: mlctrez <mlctrez@noreply@mills.io>
Co-committed-by: mlctrez <mlctrez@noreply@mills.io>
2022-04-07 03:43:09 +00:00

59 lines
1.4 KiB
Go

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
}