nitter/src/views/preferences.nim

50 lines
1.5 KiB
Nim
Raw Normal View History

2021-12-27 01:37:38 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
2020-06-22 01:50:16 +00:00
import tables, macros, strutils
import karax/[karaxdsl, vdom]
2019-08-13 17:44:29 +00:00
2019-09-05 20:53:23 +00:00
import renderutils
2019-08-17 19:49:41 +00:00
import ../types, ../prefs_impl
2019-08-13 17:44:29 +00:00
macro renderPrefs*(): untyped =
result = nnkCall.newTree(
ident("buildHtml"), ident("tdiv"), nnkStmtList.newTree())
for header, options in prefList:
result[2].add nnkCall.newTree(
ident("legend"),
nnkStmtList.newTree(
nnkCommand.newTree(ident("text"), newLit(header))))
for pref in options:
2019-08-15 12:38:14 +00:00
let procName = ident("gen" & capitalizeAscii($pref.kind))
let state = nnkDotExpr.newTree(ident("prefs"), ident(pref.name))
var stmt = nnkStmtList.newTree(
nnkCall.newTree(procName, newLit(pref.name), newLit(pref.label), state))
2019-08-13 17:44:29 +00:00
case pref.kind
2019-08-15 12:38:14 +00:00
of checkbox: discard
of input: stmt[0].add newLit(pref.placeholder)
2019-10-23 09:48:08 +00:00
of select:
if pref.name == "theme":
stmt[0].add ident("themes")
else:
stmt[0].add newLit(pref.options)
2019-08-15 12:38:14 +00:00
result[2].add stmt
2019-08-13 17:44:29 +00:00
2019-10-23 09:48:08 +00:00
proc renderPreferences*(prefs: Prefs; path: string; themes: seq[string]): VNode =
2019-09-13 08:44:21 +00:00
buildHtml(tdiv(class="overlay-panel")):
2019-08-15 17:13:54 +00:00
fieldset(class="preferences"):
form(`method`="post", action="/saveprefs"):
2019-09-05 20:53:23 +00:00
refererField path
2019-08-13 17:44:29 +00:00
renderPrefs()
2021-12-27 17:05:09 +00:00
h4(class="note"):
text "Preferences are stored client-side using cookies without any personal information."
2019-08-15 23:57:36 +00:00
button(`type`="submit", class="pref-submit"):
2019-08-13 17:44:29 +00:00
text "Save preferences"
2019-08-15 17:13:54 +00:00
buttonReferer "/resetprefs", "Reset preferences", path, class="pref-reset"