From bb981df657b3d68bcf43b8eaea8e58975781cee2 Mon Sep 17 00:00:00 2001 From: Zed Date: Mon, 3 Jan 2022 02:12:51 +0100 Subject: [PATCH] Improve and simplify preferences page behavior --- src/parserutils.nim | 2 +- src/routes/preferences.nim | 2 +- src/views/general.nim | 8 +++++--- src/views/preferences.nim | 2 +- src/views/renderutils.nim | 6 ------ 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/parserutils.nim b/src/parserutils.nim index 7d21a8c..f7a5b17 100644 --- a/src/parserutils.nim +++ b/src/parserutils.nim @@ -118,7 +118,7 @@ proc getBanner*(js: JsonNode): string = if color.len > 0: return '#' & color - # use primary color from profile picture color histrogram + # use primary color from profile picture color histogram with p, js{"profile_image_extensions", "mediaColor", "r", "ok", "palette"}: if p.len > 0: let pal = p[0]{"rgb"} diff --git a/src/routes/preferences.nim b/src/routes/preferences.nim index 5e184c2..dea6ba9 100644 --- a/src/routes/preferences.nim +++ b/src/routes/preferences.nim @@ -32,7 +32,7 @@ proc createPrefRouter*(cfg: Config) = post "/resetprefs": genResetPrefs() - redirect($(parseUri("/settings") ? filterParams(request.params))) + redirect("/settings?referer=" & encodeUrl(refPath())) post "/enablehls": savePref("hlsPlayback", "on", request) diff --git a/src/views/general.nim b/src/views/general.nim index cae9147..e6425db 100644 --- a/src/views/general.nim +++ b/src/views/general.nim @@ -12,8 +12,10 @@ const lp = readFile("public/lp.svg") proc renderNavbar(cfg: Config; req: Request; rss, canonical: string): VNode = - var path = $(parseUri(req.path) ? filterParams(req.params)) - if "/status" in path: path.add "#m" + var path = req.params.getOrDefault("referer") + if path.len == 0: + path = $(parseUri(req.path) ? filterParams(req.params)) + if "/status/" in path: path.add "#m" buildHtml(nav): tdiv(class="inner-nav"): @@ -29,7 +31,7 @@ proc renderNavbar(cfg: Config; req: Request; rss, canonical: string): VNode = icon "bird", title="Open in Twitter", href=canonical a(href="https://liberapay.com/zedeus"): verbatim lp icon "info", title="About", href="/about" - iconReferer "cog", "/settings", path, title="Preferences" + icon "cog", title="Preferences", href=("/settings?referer=" & encodeUrl(path)) proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video=""; images: seq[string] = @[]; banner=""; ogTitle=""; theme=""; diff --git a/src/views/preferences.nim b/src/views/preferences.nim index 3aa2ac1..9d7ce8a 100644 --- a/src/views/preferences.nim +++ b/src/views/preferences.nim @@ -46,4 +46,4 @@ proc renderPreferences*(prefs: Prefs; path: string; themes: seq[string]): VNode button(`type`="submit", class="pref-submit"): text "Save preferences" - buttonReferer "/resetprefs", "Reset Preferences", path, class="pref-reset" + buttonReferer "/resetprefs", "Reset preferences", path, class="pref-reset" diff --git a/src/views/renderutils.nim b/src/views/renderutils.nim index 4804144..f98b53a 100644 --- a/src/views/renderutils.nim +++ b/src/views/renderutils.nim @@ -42,12 +42,6 @@ proc hiddenField*(name, value: string): VNode = proc refererField*(path: string): VNode = hiddenField("referer", path) -proc iconReferer*(icon, action, path: string, title=""): VNode = - buildHtml(form(`method`="get", action=action, class="icon-button")): - refererField path - button(`type`="submit"): - icon icon, title=title - proc buttonReferer*(action, text, path: string; class=""; `method`="post"): VNode = buildHtml(form(`method`=`method`, action=action, class=class)): refererField path