Skip to content

Commit

Permalink
enhance navbar's snackbar displaying, add server-started snackbar not…
Browse files Browse the repository at this point in the history
…ification
  • Loading branch information
krustowski committed Aug 4, 2024
1 parent 31eebe4 commit 1bc7c19
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 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.6
APP_VERSION=0.37.7
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.6"
"version": "0.37.7"
},
"host": "littr.eu",
"basePath": "/api/v1",
Expand Down
13 changes: 10 additions & 3 deletions cmd/littr/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,19 @@ func initServer() {
server.Handler = r

l.Println("starting the server...", http.StatusOK)
if posts.Streamer != nil {
posts.Streamer.SendMessage("/api/v1/posts/live", sse.SimpleMessage("server-start"))
}
go serverStartNotif()

// TODO use http.ErrServerClosed for graceful shutdown
if err := server.Serve(listener); err != nil {
panic(err)
}
}

func serverStartNotif() {
time.Sleep(time.Second * 30)

if posts.Streamer != nil {
posts.Streamer.SendMessage("/api/v1/posts/live", sse.SimpleMessage("server-start"))
}

}
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.6
// @version 0.37.7
// @description nanoblogging platform as PWA built on go-app framework
// @termsOfService https://littr.eu/tos

Expand Down
18 changes: 15 additions & 3 deletions pkg/frontend/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ func (c *flowContent) onClickLink(ctx app.Context, e app.Event) {
}

func (c *flowContent) onClickDismiss(ctx app.Context, e app.Event) {
// little hack to dismiss navbar's snackbar
snack := app.Window().GetElementByID("snackbar-general")
if !snack.IsNull() {
snack.Get("classList").Call("remove", "active")
}

ctx.Dispatch(func(ctx app.Context) {
// hotfix which ensures reply modal is not closed if there is also a snackbar/toast active
if c.toastText == "" {
Expand Down Expand Up @@ -726,12 +732,16 @@ func (c *flowContent) onClickRefresh(ctx app.Context, e app.Event) {
c.postButtonsDisabled = true
//c.pageNoToFetch = 0

c.toastText = ""

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

// little hack to dismiss navbar's snackbar
snack := app.Window().GetElementByID("snackbar-general")
if !snack.IsNull() {
snack.Get("classList").Call("remove", "active")
}

ctx.Async(func() {
// nasty hotfix, TODO
c.pageNoToFetch = 0
Expand Down Expand Up @@ -767,8 +777,10 @@ func (c *flowContent) onClickRefresh(ctx app.Context, e app.Event) {
c.refreshClicked = false
c.postButtonsDisabled = false
c.contentLoadFinished = true
})

c.toastText = ""
c.toastShow = false
})
})
}

Expand Down
12 changes: 10 additions & 2 deletions pkg/frontend/navbars.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func (h *header) onMessage(ctx app.Context, e app.Event) {
log.Println(err.Error())
}

// do not parse the message when user has live mode disabled
/*if !user.LiveMode {
return
}*/

// explode the data CSV string
slice := strings.Split(data, ",")
text := ""
Expand All @@ -77,10 +82,12 @@ func (h *header) onMessage(ctx app.Context, e app.Event) {
// server is stoping/restarting
text = "server is restarting..."
break

case "server-start":
// server is booting up
text = "server has just started"
break

case "post":
author := slice[1]
if author == user.Nickname {
Expand All @@ -93,16 +100,17 @@ func (h *header) onMessage(ctx app.Context, e app.Event) {

text = "new post added by " + author
break

case "poll":
text = "new poll has been added"
break
}

// show the snack bar the nasty way
snack := app.Window().GetElementByID("snackbar-general")
if !snack.IsNull() {
snack.Set("innerText", text)
if !snack.IsNull() && text != "" {
snack.Get("classList").Call("add", "active")
snack.Set("innerHTML", "<i>info</i>"+text)
}

/*ctx.Dispatch(func(ctx app.Context) {
Expand Down

0 comments on commit 1bc7c19

Please sign in to comment.