From dbe1ff683ad75f1042a80c5a7bf77896c0a849b0 Mon Sep 17 00:00:00 2001 From: borntolurk Date: Fri, 19 May 2023 13:51:49 +0000 Subject: [PATCH] Preserve selected tab in navigation bar on all pages (#150) Now if user goes to new and then goes to the second, third, etc. page the 'New' tab keeps being selected instead of getting changed to 'Home' Co-authored-by: borntolurk Reviewed-on: https://fsdfsd.net/rDrama/rDrama/pulls/150 Co-authored-by: borntolurk Co-committed-by: borntolurk --- files/routes/jinja2.py | 19 +++++++++++++++++++ files/templates/mobile_navigation_bar.html | 14 +++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/files/routes/jinja2.py b/files/routes/jinja2.py index 44815dfaa..dc4c016db 100644 --- a/files/routes/jinja2.py +++ b/files/routes/jinja2.py @@ -57,6 +57,25 @@ def template_asset_siteimg(asset_path): def timestamp(timestamp): return make_age_string(timestamp) +@app.template_filter("selected_tab") +def selected_tab(request): + if request.path == '/': + requested_sort = request.args.get('sort') + if g.v and g.v.defaultsorting == 'new' and requested_sort == 'hot': + return 'hot' + elif requested_sort == 'new': + return 'new' + elif request.path == '/comments': + return 'comments' + elif request.path == '/leaderboard': + return 'leaderboard' + elif request.path == '/chat': + return 'chat' + elif request.path=='/shop/awards': + return 'shop' + + return 'home' + @app.context_processor def calc_users(): loggedin_counter = 0 diff --git a/files/templates/mobile_navigation_bar.html b/files/templates/mobile_navigation_bar.html index bf95871ca..ba9699605 100644 --- a/files/templates/mobile_navigation_bar.html +++ b/files/templates/mobile_navigation_bar.html @@ -4,7 +4,7 @@