Skip to content

Commit

Permalink
update Makefile version target, add custom toast/snackbar text on no …
Browse files Browse the repository at this point in the history
…content
  • Loading branch information
krustowski committed Jul 15, 2024
1 parent 60465c3 commit f87343c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 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.35.9
APP_VERSION=0.34.10
GOLANG_VERSION=1.22
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ stop:

.PHONY: version
version:
@[ -f "./.env" ] && cat .env | \
@[ -f "./.env" ] && head -n 7 .env | \
sed -e 's/\(APP_PEPPER\)=\(.*\)/\1=xxx/' | \
sed -e 's/\(REGISTRY\)=\(.*\)/\1=""/' | \
sed -e 's/\(MAIL_SASL_USR\)=\(.*\)/\1=xxx/' | \
Expand Down
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.35.9"
"version": "0.34.10"
},
"host": "littr.n0p.cz",
"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.35.9
// @version 0.34.10
// @description nanoblogging platform as PWA built on go-app framework
// @termsOfService https://littr.n0p.cz/tos

Expand Down
8 changes: 8 additions & 0 deletions pkg/frontend/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ type pageOptions struct {

func (c *flowContent) fetchFlowPage(opts pageOptions) (map[string]models.Post, map[string]models.User) {
var toastText string
var toastType string

resp := struct {
Posts map[string]models.Post `json:"posts"`
Expand Down Expand Up @@ -780,9 +781,16 @@ func (c *flowContent) fetchFlowPage(opts pageOptions) (map[string]models.Post, m
ctx.LocalStorage().Set("authGranted", false)
}

if len(resp.Posts) < 1 {
toastText = "no posts to show; try adding some folks to your flow, or create a new post!"
toastType = "info"
}

ctx.Dispatch(func(ctx app.Context) {
c.refreshClicked = false
c.toastText = toastText
c.toastType = toastType

c.key = resp.Key
if resp.Key != "" {
c.user = c.users[resp.Key]
Expand Down
33 changes: 31 additions & 2 deletions pkg/frontend/polls.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type pollsContent struct {

toastShow bool
toastText string
toastType string

paginationEnd bool
pagination int
Expand All @@ -60,7 +61,8 @@ func (c *pollsContent) dismissToast(ctx app.Context, e app.Event) {
func (c *pollsContent) OnNav(ctx app.Context) {
// show loader
c.loaderShow = true
toastText := ""
var toastText string
var toastType string

ctx.Async(func() {
var enUser string
Expand Down Expand Up @@ -119,6 +121,18 @@ func (c *pollsContent) OnNav(ctx app.Context) {
return
}

if len(pollsRaw.Polls) < 1 {
toastText = "no polls to show, go create one!"
toastType = "info"

ctx.Dispatch(func(ctx app.Context) {
c.toastText = toastText
c.toastType = toastType
c.toastShow = (toastText != "")
})
return
}

// Storing HTTP response in component field:
ctx.Dispatch(func(ctx app.Context) {
c.loggedUser = user.Nickname
Expand Down Expand Up @@ -280,6 +294,21 @@ func contains(s []string, str string) bool {
}

func (c *pollsContent) Render() app.UI {
toastColor := ""

switch c.toastType {
case "success":
toastColor = "green10"
break

case "info":
toastColor = "blue10"
break

default:
toastColor = "red10"
}

var sortedPolls []models.Poll

for _, sortedPoll := range c.polls {
Expand Down Expand Up @@ -336,7 +365,7 @@ func (c *pollsContent) Render() app.UI {
// snackbar
app.A().OnClick(c.dismissToast).Body(
app.If(c.toastText != "",
app.Div().Class("snackbar red10 white-text top active").Body(
app.Div().Class("snackbar "+toastColor+" white-text top active").Body(
app.I().Text("error"),
app.Span().Text(c.toastText),
),
Expand Down

0 comments on commit f87343c

Please sign in to comment.