Make theme persistant
This commit is contained in:
parent
f90a4dddba
commit
0288150c6e
1 changed files with 8 additions and 3 deletions
|
@ -62,7 +62,7 @@ class MainTemplate(private val theme: Theme) : Template<HTML> {
|
|||
div("footer-theme") {
|
||||
for (it in Theme.values()) {
|
||||
val name = it.name.toLowerCase()
|
||||
a("?theme=$name", classes = if (theme == it) "selected" else "") {
|
||||
a("?theme=${it.name}", classes = if (theme == it) "selected" else "") {
|
||||
id = "theme-$name"
|
||||
+name.capitalize()
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ enum class Theme {
|
|||
LIGHT, DARK
|
||||
}
|
||||
|
||||
private fun String?.toTheme() = this?.toUpperCase()?.let { str ->
|
||||
private fun String?.toTheme() = this?.let { str ->
|
||||
Theme.values().find { str == it.name }
|
||||
} ?: Theme.LIGHT
|
||||
|
||||
|
@ -86,7 +86,12 @@ suspend fun PipelineContext<Unit, ApplicationCall>.respondMain(body: MainTemplat
|
|||
val param = call.request.queryParameters["theme"]
|
||||
|
||||
if (param != null) {
|
||||
call.response.cookies.append("theme", param.toTheme().name.toLowerCase())
|
||||
call.response.cookies.append(
|
||||
name = "theme",
|
||||
value = param.toTheme().name,
|
||||
maxAge = Int.MAX_VALUE,
|
||||
path = "/"
|
||||
)
|
||||
call.respondRedirect(call.request.path())
|
||||
} else {
|
||||
call.respondHtmlTemplate(
|
||||
|
|
Loading…
Reference in a new issue