From 089c3c4413571f08981fb8b2f2783fcfa8e5576a Mon Sep 17 00:00:00 2001 From: "niklastasler@gmail.com" Date: Thu, 28 Dec 2023 16:06:13 +0100 Subject: [PATCH] feat: poll for changed data every 10 seconds --- internal/api/handler.go | 10 ++++++++++ main.go | 1 + templates/GameDetails.templ | 23 ++++++++++++++++++----- templates/GameDetails_templ.go | 19 ++++++++++++++++--- templates/GameOverview.templ | 5 +++-- templates/GameOverview_templ.go | 8 ++++++-- templates/base.templ | 2 +- templates/base_templ.go | 2 +- templates/components/game_card.templ | 5 +---- templates/components/game_card_templ.go | 4 ++-- templates/components/rounds_list.templ | 4 ---- templates/components/rounds_list_templ.go | 4 ++-- 12 files changed, 61 insertions(+), 26 deletions(-) diff --git a/internal/api/handler.go b/internal/api/handler.go index d00a032..2b3c30f 100644 --- a/internal/api/handler.go +++ b/internal/api/handler.go @@ -36,6 +36,16 @@ func (h Handler) GetIndex(c echo.Context) error { return render(c, http.StatusOK, index) } +func (h Handler) GetGameList(c echo.Context) error { + games, err := h.service.List() + if err != nil { + c.Logger().Error(err) + return err + } + gameList := component.GameList(games) + return render(c, http.StatusOK, gameList) +} + func (h Handler) GetGameDetails(c echo.Context) error { gameId := c.Param("id") diff --git a/main.go b/main.go index 2215331..4f77e91 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,7 @@ type Form struct { func registerRoutes(e *echo.Echo, handler api.Handler) { e.StaticFS("/static", echo.MustSubFS(staticAssets, "static")) e.GET("/", handler.GetIndex) + e.GET("/games", handler.GetGameList) e.POST("/games", handler.CreateGame) e.GET("/games/create", handler.GetCreateGameForm) diff --git a/templates/GameDetails.templ b/templates/GameDetails.templ index 90a52dd..3aa8005 100644 --- a/templates/GameDetails.templ +++ b/templates/GameDetails.templ @@ -2,6 +2,7 @@ package template import "github.com/tarow/skat-counter/internal/skat" import "github.com/tarow/skat-counter/templates/components" +import "fmt" templ GameDetailsNavbar() { -
+
- - - } templ GameList(games []skat.Game) { diff --git a/templates/components/game_card_templ.go b/templates/components/game_card_templ.go index eb21e5b..8da83fc 100644 --- a/templates/components/game_card_templ.go +++ b/templates/components/game_card_templ.go @@ -107,7 +107,7 @@ func GameCard(game skat.Game, detailsBtn, editBtn, deleteBtn bool) templ.Compone if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -163,7 +163,7 @@ func GameCard(game skat.Game, detailsBtn, editBtn, deleteBtn bool) templ.Compone return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/templates/components/rounds_list.templ b/templates/components/rounds_list.templ index 6a504f5..e26f364 100644 --- a/templates/components/rounds_list.templ +++ b/templates/components/rounds_list.templ @@ -42,7 +42,6 @@ templ RoundsList(game skat.Game) {
  • @@ -75,9 +74,6 @@ templ RoundsList(game skat.Game) { - -
    - } templ AddRoundForm(game skat.Game) { diff --git a/templates/components/rounds_list_templ.go b/templates/components/rounds_list_templ.go index 0930e08..4384771 100644 --- a/templates/components/rounds_list_templ.go +++ b/templates/components/rounds_list_templ.go @@ -121,7 +121,7 @@ func RoundsList(game skat.Game) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-swap=\"outerHTML\" hx-target=\"closest body\">
  • ") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-target=\"closest body\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -191,7 +191,7 @@ func RoundsList(game skat.Game) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
    ") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }