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/hello.go

96 lines
2.1 KiB
Go
Raw Normal View History

package components
import (
2022-03-22 04:43:05 +00:00
"fmt"
"github.com/maxence-charriere/go-app/v9/pkg/app"
2022-03-22 04:43:05 +00:00
"github.com/maxence-charriere/go-app/v9/pkg/ui"
)
const (
2022-03-22 04:43:05 +00:00
menuWidth = 282
introText = "Hello! Welcome to Salty IM 🧂 This PWA App is not quite ready yet! Come back later 🤞"
2022-03-22 04:43:05 +00:00
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
2022-03-22 04:43:05 +00:00
name string
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(fmt.Sprintf("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()
}
2022-03-22 04:43:05 +00:00
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 {
2022-03-22 04:43:05 +00:00
return app.Main().
Body(
app.H1().Text(introText),
app.If(h.isAppInstallable,
app.Button().
Text("Install App").
OnClick(h.onInstallButtonClicked),
),
2022-03-22 04:43:05 +00:00
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(),
),
)
}
func (h *Hello) onInstallButtonClicked(ctx app.Context, e app.Event) {
ctx.ShowAppInstallPrompt()
}