From 113d5860ffa08b73a6c156938225596703033fcc Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Wed, 1 Nov 2023 22:49:15 +0500 Subject: [PATCH] Keep settings page position after editing (#6) --- templates/settings.html.tmpl | 76 ++++++++++++++++++------------------ views/groups.go | 5 ++- views/links.go | 5 ++- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/templates/settings.html.tmpl b/templates/settings.html.tmpl index 22fe40b..8fe8f1a 100644 --- a/templates/settings.html.tmpl +++ b/templates/settings.html.tmpl @@ -9,7 +9,7 @@ Main page {{range .groups}} -

Group "{{.Name}}"

+

Group "{{.Name}}"

{{range .Links}} -
- - - - - - - -
- -
+ {{end}} diff --git a/views/groups.go b/views/groups.go index ee2896d..ce1d7db 100644 --- a/views/groups.go +++ b/views/groups.go @@ -1,6 +1,7 @@ package views import ( + "fmt" "github.com/gin-gonic/gin" "github.com/ordinary-dev/phoenix/database" "gorm.io/gorm" @@ -20,7 +21,7 @@ func CreateGroup(db *gorm.DB) gin.HandlerFunc { } // This page is called from the settings, return the user back. - ctx.Redirect(http.StatusFound, "/settings") + ctx.Redirect(http.StatusFound, fmt.Sprintf("/settings#group-%v", group.ID)) } } @@ -45,7 +46,7 @@ func UpdateGroup(db *gorm.DB) gin.HandlerFunc { } // This page is called from the settings, return the user back. - ctx.Redirect(http.StatusFound, "/settings") + ctx.Redirect(http.StatusFound, fmt.Sprintf("/settings#group-%v", group.ID)) } } diff --git a/views/links.go b/views/links.go index 8b7fd68..bba20d7 100644 --- a/views/links.go +++ b/views/links.go @@ -1,6 +1,7 @@ package views import ( + "fmt" "github.com/gin-gonic/gin" "github.com/ordinary-dev/phoenix/database" "gorm.io/gorm" @@ -33,7 +34,7 @@ func CreateLink(db *gorm.DB) gin.HandlerFunc { } // Redirect to settings. - ctx.Redirect(http.StatusFound, "/settings") + ctx.Redirect(http.StatusFound, fmt.Sprintf("/settings#link-%v", link.ID)) } } @@ -65,7 +66,7 @@ func UpdateLink(db *gorm.DB) gin.HandlerFunc { } // Redirect to settings. - ctx.Redirect(http.StatusFound, "/settings") + ctx.Redirect(http.StatusFound, fmt.Sprintf("/settings#link-%v", link.ID)) } }