diff --git a/wasm/app.go b/wasm/app.go index 2c712d7..49d142b 100644 --- a/wasm/app.go +++ b/wasm/app.go @@ -27,6 +27,8 @@ type crdView struct { content []byte comment bool minimal bool + + navigateBackOnClick func(ctx app.Context, _ app.Event) } // Version wraps a top level version resource which contains the underlying openAPIV3Schema. @@ -195,7 +197,7 @@ func (h *crdView) Render() app.UI { return wrapper.Body( app.Script().Src("https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js"), app.Script().Src("https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js"), - &header{}, + &header{titleOnClick: h.navigateBackOnClick, hidden: false}, container, ) } diff --git a/wasm/index.go b/wasm/index.go index 9428373..f40cb4d 100644 --- a/wasm/index.go +++ b/wasm/index.go @@ -42,21 +42,36 @@ type title struct { } func (b *title) Render() app.UI { - return app.Div().Class("title").Text("CRD Parser").OnClick(b.OnClick) -} - -func (b *title) OnClick(ctx app.Context, _ app.Event) { - ctx.Reload() + return app.Div().Class("title").Text("CRD Parser") } // header is the site header. type header struct { app.Compo + + titleOnClick func(ctx app.Context, _ app.Event) + hidden bool +} + +type backButton struct { + app.Compo + + hidden bool + onClick func(ctx app.Context, _ app.Event) +} + +func (b *backButton) Render() app.UI { + return app.Ul().Body( + app.Li().Body( + app.A().Href("#").Body( + app.I().Class("fa fa-arrow-left fa-2x")), + )).Hidden(b.hidden).OnClick(b.onClick) } func (h *header) Render() app.UI { return app.Header().Body(app.Nav().Body( &title{}, + &backButton{onClick: h.titleOnClick, hidden: h.hidden}, app.Ul().Body( app.Li().Body( app.A().Href("https://github.com/Skarlso/crd-to-sample-yaml").Target("_blank").Body( @@ -200,19 +215,23 @@ func (i *index) OnMount(_ app.Context) { i.isMounted = true } +func (i *index) NavBackOnClick(_ app.Context, _ app.Event) { + i.content = nil +} + func (i *index) Render() app.UI { // Prevent double rendering components. if i.isMounted { return app.Main().Body(app.Div().Class("container").Body(func() app.UI { if i.err != nil { - return app.Div().Class("container").Body(&header{}, i.buildError()) + return app.Div().Class("container").Body(&header{titleOnClick: i.NavBackOnClick, hidden: true}, i.buildError()) } if i.content != nil { - return &crdView{content: i.content, comment: i.comments, minimal: i.minimal} + return &crdView{content: i.content, comment: i.comments, minimal: i.minimal, navigateBackOnClick: i.NavBackOnClick} } - return app.Div().Class("container").Body(&header{}, &form{formHandler: i.OnClick, checkHandlerComment: i.OnCheckComment, checkHandlerMinimal: i.OnCheckMinimal}) + return app.Div().Class("container").Body(&header{titleOnClick: i.NavBackOnClick, hidden: true}, &form{formHandler: i.OnClick, checkHandlerComment: i.OnCheckComment, checkHandlerMinimal: i.OnCheckMinimal}) }())) } diff --git a/wasm/index.html b/wasm/index.html index d3bf2d0..fff04b4 100644 --- a/wasm/index.html +++ b/wasm/index.html @@ -7,27 +7,27 @@ - + Preview CRDs - - + + - + - - + + - + - + @@ -64,7 +64,7 @@
\ No newline at end of file diff --git a/wasm/share.html b/wasm/share.html index 7109efb..3045fa9 100644 --- a/wasm/share.html +++ b/wasm/share.html @@ -1,21 +1,21 @@ - + - + - + - + Preview CRDs - - + + @@ -23,12 +23,12 @@ - - + + - + - + @@ -66,8 +66,8 @@

Oops!

url parameter has to be define in the following format: /share?url=https://example.com/crd.yaml -