Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0

Fix theme toggler that didn't behave as intended

Fix theme toggler that didn't behave as intended when the user was logged in and his theme cookie had a different value than his user theme setting
Cette révision appartient à :
kilo 2017-11-29 11:19:53 +01:00 révisé par GitHub
Parent 28c386d35d
révision 03ba41cae3
Signature inconnue de Forgejo
ID de la clé GPG: 4AEE18F83AFDEB23
1 fichiers modifiés avec 11 ajouts et 8 suppressions

Voir le fichier

@ -7,26 +7,29 @@ import (
"github.com/NyaaPantsu/nyaa/controllers/router" "github.com/NyaaPantsu/nyaa/controllers/router"
"github.com/NyaaPantsu/nyaa/utils/timeHelper" "github.com/NyaaPantsu/nyaa/utils/timeHelper"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
) )
// toggleThemeHandler : Controller to switch between theme1 & theme2 // toggleThemeHandler : Controller to switch between theme1 & theme2
func toggleThemeHandler(c *gin.Context) { func toggleThemeHandler(c *gin.Context) {
theme, err := c.Cookie("theme") DefaultTheme := config.DefaultTheme(false)
if err != nil { DefaultDarkTheme := config.DefaultTheme(true)
theme = config.DefaultTheme(false)
} theme := publicSettings.GetThemeFromRequest(c)
theme2, err := c.Cookie("theme2") theme2, err := c.Cookie("theme2")
if err != nil { if err != nil {
theme2 = config.DefaultTheme(true) theme2 = publicSettings.GetDarkThemeFromRequest(c)
} }
if theme != config.DefaultTheme(true) && theme2 != config.DefaultTheme(true) {
if theme != DefaultDarkTheme && theme2 != DefaultDarkTheme {
//None of the themes are dark ones, force the second one as the dark one //None of the themes are dark ones, force the second one as the dark one
theme2 = config.DefaultTheme(true) theme2 = DefaultDarkTheme
} else if theme == theme2 { } else if theme == theme2 {
//Both theme are dark ones, force the second one as the default (light) theme //Both theme are dark ones, force the second one as the default (light) theme
theme2 = config.DefaultTheme(false) theme2 = DefaultTheme
} }
//Get theme1 & theme2 value //Get theme1 & theme2 value