From 1a0f8e6604f0d8b5b17c2935bfa8bdec5eeb0f1a Mon Sep 17 00:00:00 2001 From: kilo Date: Tue, 22 Aug 2017 02:49:43 +0200 Subject: [PATCH] Add failsafe to prevent theme1 & theme2 being dentical at time (#1385) * Add failsafe for theme toggle * remove unneeded / --- controllers/themeToggle/themeToggle.go | 11 ++++++++++- templates/layouts/partials/base.jet.html | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/controllers/themeToggle/themeToggle.go b/controllers/themeToggle/themeToggle.go index 7e3e6348..a154d9a2 100644 --- a/controllers/themeToggle/themeToggle.go +++ b/controllers/themeToggle/themeToggle.go @@ -12,7 +12,6 @@ import ( // toggleThemeHandler : Controller to switch between theme1 & theme2 func toggleThemeHandler(c *gin.Context) { - //Get theme1 & theme2 value, set g.css & tomorrow.css by default theme, err := c.Cookie("theme") if err != nil { theme = "g" @@ -21,6 +20,16 @@ func toggleThemeHandler(c *gin.Context) { if err != nil { theme2 = "tomorrow" } + if theme == theme2 { + if theme == "tomorrow" { + theme2 = "g" + } + if theme != "tomorrow" { + theme2 = "tomorrow" + } + } + //Get theme1 & theme2 value, set g.css & tomorrow.css by default + //Also check if both theme are identical which can happen at time //Switch theme & theme2 value http.SetCookie(c.Writer, &http.Cookie{Name: "theme", Value: theme2, Domain: getDomainName(), Path: "/", Expires: timeHelper.FewDaysLater(365)}) diff --git a/templates/layouts/partials/base.jet.html b/templates/layouts/partials/base.jet.html index 8701ed49..47d41b76 100644 --- a/templates/layouts/partials/base.jet.html +++ b/templates/layouts/partials/base.jet.html @@ -84,7 +84,7 @@