Skip to content

Commit

Permalink
add titles to navbar links, lock those links on non-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
krustowski committed Aug 4, 2024
1 parent 1bc7c19 commit d25a38d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#

APP_NAME=litter-go
APP_VERSION=0.37.7
APP_VERSION=0.37.8
GOLANG_VERSION=1.22
2 changes: 1 addition & 1 deletion api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "MIT",
"url": "https://github.com/krustowski/litter-go/blob/master/LICENSE"
},
"version": "0.37.7"
"version": "0.37.8"
},
"host": "littr.eu",
"basePath": "/api/v1",
Expand Down
2 changes: 1 addition & 1 deletion pkg/backend/router.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @title litter-go
// @version 0.37.7
// @version 0.37.8
// @description nanoblogging platform as PWA built on go-app framework
// @termsOfService https://littr.eu/tos

Expand Down
49 changes: 39 additions & 10 deletions pkg/frontend/navbars.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type header struct {

type footer struct {
app.Compo

authGranted bool
}

const (
Expand Down Expand Up @@ -197,6 +199,13 @@ func (h *header) OnMount(ctx app.Context) {
}))
}

func (f *footer) OnMount(ctx app.Context) {
var authGranted bool
ctx.LocalStorage().Get("authGranted", &authGranted)

f.authGranted = authGranted
}

func (h *header) OnAppInstallChange(ctx app.Context) {
ctx.Dispatch(func(ctx app.Context) {
h.appInstallable = ctx.IsAppInstallable()
Expand Down Expand Up @@ -310,17 +319,23 @@ func (h *header) Render() app.UI {
toastText = "new post added to the flow"
}

settingsHref := "/settings"

if !h.authGranted {
settingsHref = "#"
}

return app.Nav().ID("nav-top").Class("top fixed-top center-align").Style("opacity", "1.0").
//Style("background-color", navbarColor).
Body(
app.A().Href("/settings").Text("settings").Class("max").Body(
app.A().Href(settingsHref).Text("settings").Class("max").Title("settings").Aria("label", "settings").Body(
app.I().Class("large").Class("deep-orange-text").Body(
app.Text("build")),
),

// show intallation button if available
app.If(h.appInstallable,
app.A().Class("max").Text("install").OnClick(h.onInstallButtonClicked).Body(
app.A().Class("max").Text("install").OnClick(h.onInstallButtonClicked).Title("install").Aria("label", "install").Body(
app.I().Class("large").Class("deep-orange-text").Body(
app.Text("download"),
),
Expand Down Expand Up @@ -444,7 +459,7 @@ func (h *header) Render() app.UI {

// update button
app.If(h.updateAvailable,
app.A().Class("max").Text("update").OnClick(h.onClickReload).Body(
app.A().Class("max").Text("update").OnClick(h.onClickReload).Title("update").Aria("label", "update").Body(
app.I().Class("large").Class("deep-orange-text").Body(
app.Text("update"),
),
Expand All @@ -456,12 +471,12 @@ func (h *header) Render() app.UI {

// login/logout button
app.If(h.authGranted,
app.A().Text("logout").Class("max").OnClick(h.onClickShowLogoutModal).Body(
app.A().Text("logout").Class("max").OnClick(h.onClickShowLogoutModal).Title("logout").Aria("label", "logout").Body(
app.I().Class("large").Class("deep-orange-text").Body(
app.Text("logout")),
),
).Else(
app.A().Href("/login").Text("login").Class("max").Body(
app.A().Href("/login").Text("login").Class("max").Title("login").Aria("label", "login").Body(
app.I().Class("large").Class("deep-orange-text").Body(
app.Text("login")),
),
Expand All @@ -471,29 +486,43 @@ func (h *header) Render() app.UI {

// bottom navbar
func (f *footer) Render() app.UI {
statsHref := "/stats"
usersHref := "/users"
postHref := "/post"
pollsHref := "/polls"
flowHref := "/flow"

if !f.authGranted {
statsHref = "#"
usersHref = "#"
postHref = "#"
pollsHref = "#"
flowHref = "#"
}

return app.Nav().ID("nav-top").Class("bottom fixed-top center-align").Style("opacity", "1.0").
Body(
app.A().Href("/stats").Text("stats").Class("max").Body(
app.A().Href(statsHref).Text("stats").Class("max").Title("stats").Aria("label", "stats").Body(
app.I().Class("large deep-orange-text").Body(
app.Text("query_stats")),
),

app.A().Href("/users").Text("users").Class("max").Body(
app.A().Href(usersHref).Text("users").Class("max").Title("users").Aria("label", "users").Body(
app.I().Class("large deep-orange-text").Body(
app.Text("group")),
),

app.A().Href("/post").Text("post").Class("max").Body(
app.A().Href(postHref).Text("post").Class("max").Title("new post/poll").Aria("label", "new post/poll").Body(
app.I().Class("large deep-orange-text").Body(
app.Text("add")),
),

app.A().Href("/polls").Text("polls").Class("max").Body(
app.A().Href(pollsHref).Text("polls").Class("max").Title("polls").Aria("label", "polls").Body(
app.I().Class("large deep-orange-text").Body(
app.Text("equalizer")),
),

app.A().Href("/flow").Text("flow").Class("max").Body(
app.A().Href(flowHref).Text("flow").Class("max").Title("flow").Aria("label", "flow").Body(
app.I().Class("large deep-orange-text").Body(
app.Text("tsunami")),
),
Expand Down

0 comments on commit d25a38d

Please sign in to comment.