2022-03-21 22:27:35 +00:00
package components
import (
2022-03-22 04:43:05 +00:00
"fmt"
2022-03-21 22:27:35 +00:00
"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"
2022-03-21 22:27:35 +00:00
)
2022-03-22 04:04:47 +00:00
const (
2022-03-22 04:43:05 +00:00
menuWidth = 282
2022-03-22 04:04:47 +00:00
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. `
2022-03-22 04:04:47 +00:00
)
// Hello is a component that displays a simple "Hello World!". A component is a
2022-03-21 22:27:35 +00:00
// 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:04:47 +00:00
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 ( )
2022-03-22 04:04:47 +00:00
}
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 ( )
}
2022-03-22 04:04:47 +00:00
func ( h * Hello ) OnMount ( ctx app . Context ) {
h . isAppInstallable = ctx . IsAppInstallable ( )
2022-03-21 22:27:35 +00:00
}
func ( h * Hello ) Render ( ) app . UI {
2022-03-22 04:43:05 +00:00
return app . Main ( ) .
2022-03-22 04:04:47 +00:00
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 ( ) ,
) ,
2022-03-22 04:04:47 +00:00
)
}
func ( h * Hello ) onInstallButtonClicked ( ctx app . Context , e app . Event ) {
ctx . ShowAppInstallPrompt ( )
2022-03-21 22:27:35 +00:00
}