2022-03-28 21:49:01 +00:00
|
|
|
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"
|
2022-03-30 00:35:43 +00:00
|
|
|
"go.mills.io/saltyim/internal/pwa/storage"
|
2022-03-31 00:51:38 +00:00
|
|
|
"go.mills.io/saltyim/internal/pwa/utils"
|
2022-03-28 21:49:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type NewChat struct {
|
|
|
|
app.Compo
|
|
|
|
base.JsUtil
|
|
|
|
|
2022-04-07 03:43:09 +00:00
|
|
|
dialog *ModalDialog
|
2022-03-28 21:49:01 +00:00
|
|
|
|
|
|
|
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{}
|
|
|
|
}
|
|
|
|
|
2022-04-07 03:43:09 +00:00
|
|
|
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,
|
|
|
|
),
|
2022-03-28 21:49:01 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *NewChat) newChat() func(button app.HTMLButton) {
|
|
|
|
return func(button app.HTMLButton) {
|
|
|
|
button.OnClick(func(ctx app.Context, e app.Event) {
|
2022-03-31 00:51:38 +00:00
|
|
|
addr, err := utils.LookupAddr(n.user.Value)
|
2022-03-28 21:49:01 +00:00
|
|
|
if err != nil {
|
2022-04-04 16:04:38 +00:00
|
|
|
n.dialog.ShowError("error", err.Error())
|
2022-03-28 21:49:01 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-30 00:35:43 +00:00
|
|
|
storage.ContactsLocalStorage(ctx).Add(addr.String())
|
2022-03-28 21:49:01 +00:00
|
|
|
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
|
|
|
|
}
|