6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-07-08 11:01:20 +00:00
prologic-saltyim/internal/pwa/components/hello.go
2022-03-22 15:44:54 +10:00

107 lines
2.4 KiB
Go

package components
import (
"github.com/maxence-charriere/go-app/v9/pkg/app"
"github.com/maxence-charriere/go-app/v9/pkg/ui"
banner "github.com/mlctrez/goapp-mdc/pkg/banner"
bar "github.com/mlctrez/goapp-mdc/pkg/bar"
button "github.com/mlctrez/goapp-mdc/pkg/button"
)
const (
menuWidth = 282
introText = "Hello! Welcome to Salty IM 🧂 This PWA App is not quite ready yet! Come back later 🤞"
descText = `salty.im is an open specification for a new Saltpack based e2e encrypted messaging protocol and platform for secure communications with a focus on privacy, security and being self-hosted.`
)
// Hello is a component that displays a simple "Hello World!". A component is a
// customizable, independent, and reusable UI element. It is created by
// embedding app.Compo into a struct.
type Hello struct {
app.Compo
isUpdateAvailable bool
isAppInstallable bool
}
func (h *Hello) init(ctx app.Context) {
}
func (h *Hello) load(ctx app.Context) {
h.isUpdateAvailable = ctx.AppUpdateAvailable()
ctx.Page().SetTitle("Salty Chat")
ctx.Page().SetDescription(descText)
}
func (h *Hello) onUpdateClick(ctx app.Context) {
ctx.Reload()
}
func (h *Hello) OnPreRender(ctx app.Context) {
h.init(ctx)
h.load(ctx)
}
func (h *Hello) OnResize(ctx app.Context) {
h.ResizeContent()
}
func (h *Hello) OnAppInstallChange(ctx app.Context) {
h.isAppInstallable = ctx.IsAppInstallable()
}
func (h *Hello) OnAppUpdate(ctx app.Context) {
h.isUpdateAvailable = ctx.AppUpdateAvailable()
}
func (h *Hello) OnMount(ctx app.Context) {
h.isAppInstallable = ctx.IsAppInstallable()
}
func (h *Hello) Render() app.UI {
return app.Main().
Body(
&banner.Banner{
Fixed: true,
Centered: true,
Text: "WARNING: This is work-in-progress!",
},
&bar.TopAppBar{
Title: "Salty IM",
},
app.H1().Text(introText),
app.H2().Text("Testing update #1"),
app.If(h.isAppInstallable,
app.Button().
Text("Install App").
OnClick(h.onInstallButtonClicked),
),
ui.Shell().
PaneWidth(menuWidth).
HamburgerMenu().
Content(
app.Aside().
Body(
ui.Stack().
Right().
Middle().
Content(
app.If(h.isUpdateAvailable,
newLink().
OnClick(h.onUpdateClick),
),
),
),
app.Div().
Body(
&button.Button{Label: "Click me"},
),
),
)
}
func (h *Hello) onInstallButtonClicked(ctx app.Context, e app.Event) {
ctx.ShowAppInstallPrompt()
}