Skip to content

Commit

Permalink
Use hrefs for sidenav links
Browse files Browse the repository at this point in the history
This `#nav_link_js` nonsense is no longer necessary after #45.

fixes #46
  • Loading branch information
vinnydiehl committed Jun 18, 2023
1 parent 0403e55 commit 62c72f6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def init_globals

def set_current_user
@current_user = User.find_by google_id: cookies.encrypted[:google_id]
STDERR.puts "DEBUGPRINT[2]: application_controller.rb:19: @current_user=#{@current_user}"
end

def turbo_request_variant
Expand Down
14 changes: 1 addition & 13 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ def time_since_deploy
time_ago_in_words File.mtime("app"), include_seconds: true
end

# Generates JavaScript for the onclick of a nav link. This ensures that the sidenav
# closes
#
# @param path [String] the path to link to
# @return [String] JavaScript to close the sidenav and redirect to the path
def nav_link_js(path)
"if (window.innerWidth <= 992) {" \
"M.Sidenav.getInstance(document.querySelector('#sidenav')).close();" \
"window.location.href = '#{path}'" \
"} else Turbo.visit('#{path}')"
end

# Generates a nav link for the sidenav, with an icon and optional text.
#
# @param icon [String] material-icons ligature
Expand All @@ -45,7 +33,7 @@ def nav_link(icon, path, text = "")
attrs = { class: "bold#{request.path.starts_with?(path) ? ' active' : ''}" }

content_tag(:li, attrs) do
content_tag(:a, onclick: nav_link_js(path), class: "waves-effect") do
content_tag(:a, href: path, class: "waves-effect sidenav-close") do
content_tag(:i, icon, class: "material-icons").concat(content_tag :div, text)
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/views/layouts/_sidenav.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%ul#sidenav.sidenav.sidenav-fixed{style: "transform: translateX(0px);", "data-controller": "sidenav"}
%li.logo
%a#logo-container.waves-effect{onclick: nav_link_js("/home")}
= link_to "/home", id: "logo-container", class: "waves-effect sidenav-close" do
= image_tag "logo.svg", height: 120, id: "front-page-logo"
- if logged_in?
%ul.collapsible{"data-controller": "collapsible"}
Expand All @@ -9,9 +9,9 @@
.collapsible-body
%ul
%li
%a.waves-effect{onclick: nav_link_js(user_path @current_user)} Profile
= link_to "Profile", @current_user, class: "waves-effect sidenav-close"
%li
%a.waves-effect{onclick: nav_link_js("/logout")} Logout
= link_to "Logout", "/logout", class: "waves-effect sidenav-close"
- else
%li#sign-in
%a.sign-in= render "layouts/google_sign_in_button"
Expand Down

0 comments on commit 62c72f6

Please sign in to comment.