From 8f3d9351ed05c90bca7a28fa2f8f590e0ee96859 Mon Sep 17 00:00:00 2001 From: Araozu Date: Sun, 8 Dec 2024 18:08:00 -0500 Subject: [PATCH] feat: add refresh button to random albums --- src/modules/index/index.go | 6 +++++ src/modules/index/index.templ | 43 ++++++++++++++++++++++++++++++----- src/utils/utils.templ | 5 ++-- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/modules/index/index.go b/src/modules/index/index.go index 17942b5..4189ca2 100644 --- a/src/modules/index/index.go +++ b/src/modules/index/index.go @@ -19,11 +19,17 @@ func SetupRoutes(g *echo.Group) { } func indexPage(c echo.Context) error { + refreshQuery := c.QueryParam("refresh") + sessionToken, navidromeUrl := utils.Credentials(c) albums, err := getRandomAlbums(sessionToken, navidromeUrl, 10) if err != nil { return c.HTML(http.StatusBadRequest, fmt.Sprintf("%s", err)) } + if refreshQuery == "true" { + return utils.RenderTempl(c, http.StatusOK, RandomAlbumsFragment(albums)) + } + return utils.RenderTempl(c, http.StatusOK, IndexTempl(albums)) } diff --git a/src/modules/index/index.templ b/src/modules/index/index.templ index a5002ba..8aa5c61 100644 --- a/src/modules/index/index.templ +++ b/src/modules/index/index.templ @@ -3,6 +3,7 @@ package index import ( "acide/src/utils" "fmt" + "strconv" ) templ IndexTempl(albums []utils.Album) { @@ -15,17 +16,33 @@ templ IndexTempl(albums []utils.Album) { Albums -

+

Random Albums +

-
- for _, album := range albums { - @AlbumCard(album) - } -
+ @RandomAlbumsFragment(albums) } } +templ RandomAlbumsFragment(albums []utils.Album) { +
+ for _, album := range albums { + @AlbumCard(album) + } +
+} + templ AlbumCard(album utils.Album) {
@@ -44,3 +61,17 @@ templ AlbumCard(album utils.Album) {
} + +templ arrowClockwiseIcon(size int) { + + + +} diff --git a/src/utils/utils.templ b/src/utils/utils.templ index accbdd6..2872c63 100644 --- a/src/utils/utils.templ +++ b/src/utils/utils.templ @@ -19,8 +19,9 @@ templ SkeletonTempl() { + - +
{ children... }
@@ -79,7 +80,7 @@ templ MusicPlayer() { @fullMusicPlayer()