From 3f7ccb55250170f5341ef067c4f21a334b639470 Mon Sep 17 00:00:00 2001 From: Zed Date: Mon, 19 Aug 2019 04:37:28 +0200 Subject: [PATCH] Go back to previous page when saving settings --- src/nitter.nim | 9 +++++++-- src/views/preferences.nim | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/nitter.nim b/src/nitter.nim index 9a66357..0d737d0 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -90,7 +90,7 @@ routes: var prefs = cookiePrefs() genUpdatePrefs() setCookie("preferences", $prefs.id, daysForward(360), httpOnly=true, secure=cfg.useHttps) - redirect("/") + redirect(decodeUrl(@"referer")) post "/resetprefs": var prefs = cookiePrefs() @@ -99,7 +99,12 @@ routes: redirect("/settings") get "/settings": - resp renderMain(renderPreferences(cookiePrefs()), cfg.title, "Preferences") + let refUri = request.headers.getOrDefault("Referer").parseUri() + var path = + if refUri.path.len > 0 and "/settings" notin refUri.path: refUri.path + else: "/" + if refUri.query.len > 0: path &= &"?{refUri.query}" + resp renderMain(renderPreferences(cookiePrefs(), path), cfg.title, "Preferences") get "/@name/?": cond '.' notin @"name" diff --git a/src/views/preferences.nim b/src/views/preferences.nim index 70a0a5b..47d88ee 100644 --- a/src/views/preferences.nim +++ b/src/views/preferences.nim @@ -51,10 +51,12 @@ macro renderPrefs*(): untyped = result[2].add stmt -proc renderPreferences*(prefs: Prefs): VNode = +proc renderPreferences*(prefs: Prefs; path: string): VNode = buildHtml(tdiv(class="preferences-container")): fieldset(class="preferences"): form(`method`="post", action="saveprefs"): + verbatim "" % path + renderPrefs() button(`type`="submit", class="pref-submit"):