From 9fc512d88d776b2c73f7286321c7a13cb6631e70 Mon Sep 17 00:00:00 2001 From: Zed Date: Thu, 15 Aug 2019 19:13:54 +0200 Subject: [PATCH] Add button to reset preferences --- public/css/style.css | 13 +++++++++---- src/nitter.nim | 6 ++++++ src/prefs.nim | 6 ++++++ src/views/preferences.nim | 8 ++++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/public/css/style.css b/public/css/style.css index a633117..0963712 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -1092,10 +1092,6 @@ legend { margin: .2em; 0; } -.pref-submit:hover { - background-color: #a8a8a8; -} - .pref-submit { background-color: #e2e2e2; color: #000; @@ -1106,6 +1102,15 @@ legend { margin-top: 4px; } +.pref-submit:hover { + background-color: #a8a8a8; +} + +.pref-reset { + float: right; + margin-top: -25px; +} + .icon-container { display: inline; } diff --git a/src/nitter.nim b/src/nitter.nim index 269f560..36a7448 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -95,6 +95,12 @@ routes: setCookie("preferences", $prefs.id, daysForward(360), httpOnly=true, secure=true) redirect("/settings") + post "/resetprefs": + var prefs = getCookiePrefs(request) + resetPrefs(prefs) + setCookie("preferences", $prefs.id, daysForward(360), httpOnly=true, secure=true) + redirect("/settings") + get "/settings": let prefs = getCookiePrefs(request) resp renderMain(renderPreferences(prefs), prefs, title=cfg.title, titleText="Preferences") diff --git a/src/prefs.nim b/src/prefs.nim index f383860..825d407 100644 --- a/src/prefs.nim +++ b/src/prefs.nim @@ -96,6 +96,12 @@ proc getPrefs*(id: string): Prefs = result = genDefaultPrefs() cache(result) +proc resetPrefs*(prefs: var Prefs) = + var defPrefs = genDefaultPrefs() + defPrefs.id = prefs.id + cache(defPrefs) + prefs = defPrefs + macro genUpdatePrefs*(): untyped = result = nnkStmtList.newTree() diff --git a/src/views/preferences.nim b/src/views/preferences.nim index d9cc199..f041e8e 100644 --- a/src/views/preferences.nim +++ b/src/views/preferences.nim @@ -53,9 +53,13 @@ macro renderPrefs*(): untyped = proc renderPreferences*(prefs: Prefs): VNode = buildHtml(tdiv(class="preferences-container")): - form(class="preferences", `method`="post", action="saveprefs"): - fieldset: + fieldset(class="preferences"): + form(`method`="post", action="saveprefs"): renderPrefs() button(`type`="submit", class="pref-submit"): text "Save preferences" + + form(`method`="post", action="resetprefs", class="pref-reset"): + button(`type`="submit", class="pref-submit"): + text "Reset preferences"