39 lines
931 B
Go
39 lines
931 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"templ-test/domain"
|
|
"templ-test/models"
|
|
"templ-test/views/home"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func (h *Handlers) HomeHandler(c echo.Context) error {
|
|
return Render(c, http.StatusOK, home.Home())
|
|
}
|
|
|
|
func (h *Handlers) Settings(c echo.Context) error {
|
|
m := models.SettingsViewModel{}
|
|
darkMode, err := c.Cookie(domain.CookieSettingsDarkMode)
|
|
if err == nil {
|
|
m.DarkMode = darkMode.Value
|
|
}
|
|
|
|
return Render(c, http.StatusOK, home.UserSettings(m))
|
|
}
|
|
|
|
func (h *Handlers) SettingsPost(c echo.Context) error {
|
|
// take in the updated values from he user and write the cookies... tbd
|
|
useDarkMode := c.FormValue(domain.CookieSettingsDarkMode)
|
|
if useDarkMode != "" {
|
|
darkModeCookie := new(http.Cookie)
|
|
darkModeCookie.Name = domain.CookieSettingsDarkMode
|
|
darkModeCookie.Value = useDarkMode
|
|
|
|
c.SetCookie(darkModeCookie)
|
|
}
|
|
|
|
return Render(c, http.StatusOK, home.SettingsUpdated())
|
|
}
|