Improve and simplify preferences page behavior
This commit is contained in:
		
							parent
							
								
									ab51ff06c8
								
							
						
					
					
						commit
						bb981df657
					
				| 
						 | 
				
			
			@ -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"}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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="";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue