2024-04-09 07:29:45 -07:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2024-04-14 18:39:04 -07:00
|
|
|
"templ-test/domain"
|
|
|
|
"templ-test/models"
|
2024-04-13 11:51:31 -07:00
|
|
|
"templ-test/views/home"
|
2024-04-09 07:29:45 -07:00
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (h *Handlers) HomeHandler(c echo.Context) error {
|
2024-04-13 11:51:31 -07:00
|
|
|
return Render(c, http.StatusOK, home.Home())
|
2024-04-09 07:29:45 -07:00
|
|
|
}
|
|
|
|
|
2024-04-13 11:51:31 -07:00
|
|
|
func (h *Handlers) Settings(c echo.Context) error {
|
2024-04-14 18:39:04 -07:00
|
|
|
m := models.SettingsViewModel{}
|
|
|
|
darkMode, err := c.Cookie(domain.CookieSettingsDarkMode)
|
|
|
|
if err == nil {
|
|
|
|
m.DarkMode = darkMode.Value
|
|
|
|
}
|
|
|
|
|
|
|
|
return Render(c, http.StatusOK, home.UserSettings(m))
|
2024-04-13 11:51:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Handlers) SettingsPost(c echo.Context) error {
|
|
|
|
// take in the updated values from he user and write the cookies... tbd
|
2024-04-14 18:39:04 -07:00
|
|
|
useDarkMode := c.FormValue(domain.CookieSettingsDarkMode)
|
|
|
|
if useDarkMode != "" {
|
|
|
|
darkModeCookie := new(http.Cookie)
|
|
|
|
darkModeCookie.Name = domain.CookieSettingsDarkMode
|
|
|
|
darkModeCookie.Value = useDarkMode
|
|
|
|
|
|
|
|
c.SetCookie(darkModeCookie)
|
|
|
|
}
|
2024-04-13 11:51:31 -07:00
|
|
|
|
2024-04-14 18:39:04 -07:00
|
|
|
return Render(c, http.StatusOK, home.SettingsUpdated())
|
2024-04-13 11:51:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//func (h *Handlers) ListHandler(c echo.Context) error {
|
|
|
|
// return Render(c, http.StatusOK, views.List())
|
|
|
|
//}
|