Skip to content

Commit a300c4e

Browse files
author
Piotr Gulbinowicz
committed
add install button to pwa
1 parent 8607a9e commit a300c4e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pwa/flush/components.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323
RemoveButtonCss = "font-bold bg-red-500 p-2 rounded hover:bg-red-700 m-1"
2424
LogoutButtonCss = "font-bold bg-amber-700 p-2 rounded mx-1 hover:bg-amber-900"
2525
UpdateButtonCss = "bg-green-600 hover:bg-green-800 text-xl p-2 rounded bottom-4 right-4 fixed"
26+
InstallButtonCss = "bg-green-600 hover:bg-green-800 p-2 rounded m-2"
2627
)
2728

2829
type ErrorContainer struct {
@@ -143,6 +144,7 @@ func (b *RootContainer) Render() app.UI {
143144
Location: "new",
144145
AdditionalCss: "hover:bg-amber-800",
145146
},
147+
&InstallButton{},
146148
).ID("root-buttons-container").Class("flex flex-col absolute top-4 right-4"),
147149
app.P().Text("Tracked flushes:").Class("py-2"),
148150
&LoadingWidget{id: "flushes-loading"},
@@ -522,6 +524,7 @@ func (a *AboutContainer) Render() app.UI {
522524
Location: "login",
523525
AdditionalCss: "hover:bg-amber-800",
524526
},
527+
&InstallButton{},
525528
).Class("flex flex-col p-4 shadow-lg rounded-lg bg-zinc-800"),
526529
).Class(CenteringDivCss).ID("about-container")
527530
}
@@ -932,3 +935,30 @@ func (c *UpdateButton) Render() app.UI {
932935
func (c *UpdateButton) onUpdateClick(ctx app.Context, e app.Event) {
933936
ctx.Reload()
934937
}
938+
939+
type InstallButton struct {
940+
app.Compo
941+
name string
942+
isAppInstallable bool
943+
}
944+
945+
func (b *InstallButton) OnMount(ctx app.Context) {
946+
b.isAppInstallable = ctx.IsAppInstallable()
947+
}
948+
func (b *InstallButton) OnAppInstallChange(ctx app.Context) {
949+
b.isAppInstallable = ctx.IsAppInstallable()
950+
}
951+
func (b *InstallButton) Render() app.UI {
952+
return app.Div().
953+
Body(
954+
app.If(b.isAppInstallable, func() app.UI {
955+
return app.Button().
956+
Text("Install App").
957+
OnClick(b.onInstallButtonClicked).
958+
Class(InstallButtonCss)
959+
}),
960+
).Class("flex flex-col")
961+
}
962+
func (b *InstallButton) onInstallButtonClicked(ctx app.Context, e app.Event) {
963+
ctx.ShowAppInstallPrompt()
964+
}

0 commit comments

Comments
 (0)