Skip to content

Commit

Permalink
implement a simple EDA logic for generic toasts: refresh, redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
krustowski committed Sep 13, 2024
1 parent 7eb5016 commit 01c529b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 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=littr
APP_VERSION=0.40.7
APP_VERSION=0.40.8
GOLANG_VERSION=1.23
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/littr/blob/master/LICENSE"
},
"version": "0.40.7"
"version": "0.40.8"
},
"host": "www.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 littr
// @version 0.40.7
// @version 0.40.8
// @description a simple nanoblogging platform as PWA built on go-app framework
// @termsOfService https://littr.eu/tos

Expand Down
31 changes: 18 additions & 13 deletions pkg/frontend/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,21 @@ func (c *flowContent) onClickLink(ctx app.Context, e app.Event) {
ctx.Navigate("/flow/post/" + key)
}

func (c *flowContent) handleClear(ctx app.Context, a app.Action) {
ctx.Dispatch(func(ctx app.Context) {
c.loaderShow = true
c.loaderShowImage = true
c.contentLoadFinished = false
c.refreshClicked = true
c.postButtonsDisabled = true
//c.pageNoToFetch = 0

c.posts = nil
c.users = nil
})
return
}

func (c *flowContent) handleDismiss(ctx app.Context, a app.Action) {
ctx.Dispatch(func(ctx app.Context) {
// hotfix which ensures reply modal is not closed if there is also a snackbar/toast active
Expand Down Expand Up @@ -873,19 +888,8 @@ func (c *flowContent) handleRefresh(ctx app.Context, a app.Action) {
}

func (c *flowContent) onClickRefresh(ctx app.Context, e app.Event) {
ctx.Dispatch(func(ctx app.Context) {
c.loaderShow = true
c.loaderShowImage = true
c.contentLoadFinished = false
c.refreshClicked = true
c.postButtonsDisabled = true
//c.pageNoToFetch = 0

c.posts = nil
c.users = nil
})

ctx.NewAction("dismiss")
ctx.NewAction("clear")
ctx.NewAction("refresh")
}

Expand Down Expand Up @@ -1079,6 +1083,7 @@ func (c *flowContent) OnMount(ctx app.Context) {
ctx.Handle("reply", c.handleReply)
ctx.Handle("scroll", c.handleScroll)
ctx.Handle("star", c.handleStar)
ctx.Handle("clear", c.handleClear)
ctx.Handle("dismiss", c.handleDismiss)
ctx.Handle("refresh", c.handleRefresh)
//ctx.Handle("message", c.handleNewPost)
Expand Down Expand Up @@ -1273,7 +1278,7 @@ func (c *flowContent) Render() app.UI {
),

app.Div().Class("small-padding").Body(
app.Button().Title("refresh flow [R]").Class("border black white-text bold").Style("border-radius", "8px").OnClick(c.onClickRefresh).Disabled(c.postButtonsDisabled).Body(
app.Button().ID("refresh-button").Title("refresh flow [R]").Class("border black white-text bold").Style("border-radius", "8px").OnClick(c.onClickRefresh).Disabled(c.postButtonsDisabled).Body(
app.If(c.refreshClicked,
app.Progress().Class("circle deep-orange-border small"),
),
Expand Down
21 changes: 21 additions & 0 deletions pkg/frontend/navbars.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,27 @@ func (h *header) onClickShowLogoutModal(ctx app.Context, e app.Event) {
}

func (h *header) onClickModalDismiss(ctx app.Context, e app.Event) {
snack := app.Window().GetElementByID("snackbar-general")
if !snack.IsNull() {
if strings.Contains(snack.Get("innerText").String(), "post added") {
if ctx.Page().URL().Path == "/flow" && !app.Window().GetElementByID("refresh-button").IsNull() {
ctx.NewAction("dismiss")
ctx.NewAction("clear")
ctx.NewAction("refresh")
return
}

ctx.Navigate("/flow")
}

if strings.Contains(snack.Get("innerText").String(), "poll added") {
ctx.Navigate("/polls")
}

ctx.NewAction("dismiss-general")
return
}

ctx.NewAction("dismiss-general")
}

Expand Down

0 comments on commit 01c529b

Please sign in to comment.