app/views/navbars/_top.html.erb
<nav class="navbar bg-primary navbar-dark sticky-top mb-3">
<div class="container-fluid">
<%=
link_to root_path, class: 'navbar-brand' do
image_tag "/images/logo_#{Date.current.saturday? ? 'hex' : 's95'}.png", alt: 'Sat 9am 5km', height: 70
end
%>
<nav class="navbar navbar-expand-lg d-none d-lg-block navbar-dark me-auto">
<div class="container">
<div class="navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item dropdown" data-controller="dropdown">
<%= link_to t('.events'), '#', class: "nav-link dropdown-toggle #{'active' if params[:controller] == 'events'}", id: 'eventDropdown', role: 'button', 'data-bs-toggle' => 'dropdown', 'aria-expanded' => 'false', 'data-dropdown-target' => 'toggle' %>
<ul class="dropdown-menu" aria-labelledby="eventDropdown" data-dropdown-target="menu">
<% @country_events.each do |event| %>
<li><%= link_to event.name, event_path(event.code_name), class: 'dropdown-item' %></li>
<% end %>
</ul>
</li>
<li class="nav-item dropdown" data-controller="dropdown">
<%= link_to t('.results'), '#', class: "nav-link dropdown-toggle #{'active' if %w[activities clubs ratings].include?(params[:controller])}", id: 'dataDropdown', role: 'button', 'data-bs-toggle' => 'dropdown', 'aria-expanded' => 'false', 'data-dropdown-target' => 'toggle' %>
<ul class="dropdown-menu" aria-labelledby="dataDropdown" data-dropdown-target="menu">
<li><%= link_to t('.recent_results'), activities_path, class: 'dropdown-item' %></li>
<li><%= link_to t('.club_ratings'), clubs_path, class: 'dropdown-item' %></li>
<li><%= link_to t('.top_results'), results_ratings_path, class: 'dropdown-item' %></li>
<li><%= link_to t('.top_athletes'), ratings_path(rating_type: 'results'), class: 'dropdown-item' %></li>
<li><%= link_to t('.top_volunteers'), ratings_path(rating_type: 'volunteers'), class: 'dropdown-item' %></li>
<li><%= link_to t('.badges'), badges_path, class: 'dropdown-item' %></li>
</ul>
</li>
<li class="nav-item">
<%= link_to t('.rules'), page_path(page: :rules), class: "nav-link #{'active' if params[:page] == 'rules'}" %>
</li>
<li class="nav-item">
<%= link_to t('.about'), page_path(page: :about), class: "nav-link #{'active' if params[:page] == 'about'}" %>
</li>
<li class="nav-item">
<%= link_to t('.support'), page_path(page: :support), class: "nav-link #{'active' if params[:page] == 'support'}" %>
</li>
</ul>
</div>
</div>
</nav>
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasNavbar" aria-controls="offcanvasNavbar" aria-label="Navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="offcanvas offcanvas-end text-bg-primary" id="offcanvasNavbar" aria-labelledby="offcanvasNavbarLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasNavbarLabel">
<%= link_to 'Sat 9am 5km', root_path, class: 'link-light text-decoration-none' %>
</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body d-flex flex-column justify-content-between">
<ul class="navbar-nav justify-content-start flex-grow-1 fa-ul pe-3">
<li class="nav-item">
<%= link_to activities_path, class: "nav-link #{'active' if params[:controller] == 'activities'}" do %>
<span class="fa-li"><i class="fa-solid fa-square-poll-horizontal"></i></span><%= t '.recent_results' %>
<% end %>
</li>
<!--<li class="nav-item">
<%#= link_to t('.1_january'), page_path(page: 'additional-events'), class: "nav-link #{'active' if params[:page] == 'additional-events'}" %>
</li>-->
<li class="nav-item">
<%= link_to clubs_path, class: "nav-link #{'active' if params[:controller] == 'clubs'}" do %>
<span class="fa-li"><i class="fa-solid fa-people-group"></i></span><%= t '.club_ratings' %>
<% end %>
</li>
<li class="nav-item">
<%= link_to results_ratings_path, class: "nav-link #{'active' if params[:action] == 'results' && params[:controller] == 'ratings'}" do %>
<span class="fa-li"><i class="fa-solid fa-trophy"></i></span><%= t '.top_results' %>
<% end %>
</li>
<li class="nav-item">
<%= link_to ratings_path(rating_type: 'results'), class: "nav-link #{'active' if params[:rating_type] == 'results' && params[:controller] == 'ratings'}" do %>
<span class="fa-li"><i class="fa-solid fa-table"></i></span><%= t '.top_athletes' %>
<% end %>
</li>
<li class="nav-item">
<%= link_to ratings_path(rating_type: 'volunteers'), class: "nav-link #{'active' if params[:rating_type] == 'volunteers' && params[:controller] == 'ratings'}" do %>
<span class="fa-li"><i class="fa-solid fa-table"></i></span><%= t '.top_volunteers' %>
<% end %>
</li>
<li class="nav-item">
<%= link_to badges_path, class: "nav-link #{'active' if params[:controller] == 'badges'}" do %>
<span class="fa-li"><i class="fa-solid fa-award"></i></span><%= t '.badges' %>
<% end %>
</li>
<li class="nav-item">
<%= link_to page_path(page: :rules), class: "nav-link #{'active' if params[:page] == 'rules'}" do %>
<span class="fa-li"><i class="fa-solid fa-clipboard"></i></span><%= t '.rules' %>
<% end %>
</li>
<li class="nav-item">
<%= link_to page_path(page: :about), class: "nav-link #{'active' if params[:page] == 'about'}" do %>
<span class="fa-li"><i class="fa-solid fa-users"></i></span><%= t '.about' %>
<% end %>
</li>
<li class="nav-item">
<%= link_to page_path(page: :support), class: "nav-link #{'active' if params[:page] == 'support'}" do %>
<span class="fa-li"><i class="fa-regular fa-handshake"></i></span><%= t '.support' %>
<% end %>
</li>
<% if current_user %>
<li class="nav-item dropdown mt-3" data-controller="dropdown">
<%=
link_to(
'#',
class: "nav-link dropdown-toggle #{'active' if (params[:controller] == 'users' && params[:action] == 'show') || (params[:controller] == 'athletes' && params[:id].to_i == current_user.athlete&.id )}",
id: 'dataUserDropdown',
role: 'button',
'data-bs-toggle' => 'dropdown',
'data-dropdown-target' => 'toggle',
'aria-expanded' => 'false'
) do
%>
<span class="fa-li"><i class="fa-solid fa-user"></i></span><%= current_user.full_name %>
<% end %>
<ul class="dropdown-menu" aria-labelledby="dataUserDropdown" data-dropdown-target="menu">
<% if athlete = current_user.athlete %>
<li><%= link_to t('.profile'), athlete_path(athlete), class: 'dropdown-item' %></li>
<% end %>
<li><%= link_to t('.settings'), user_path, class: 'dropdown-item' %></li>
<% if current_user.admin? || Permission.exists?(user: current_user) %>
<li><%= link_to t('.admin_panel'), admin_root_path, class: 'dropdown-item' %></li>
<% end %>
<li><%= link_to t('.logout'), destroy_user_session_path, class: 'dropdown-item', 'data-turbo-prefetch' => 'false' %></li>
</ul>
</li>
<% else %>
<li class="nav-item mt-3">
<%= link_to new_user_session_path, class: "btn btn-outline-light" do %>
<i class="fa-solid fa-arrow-right-to-bracket me-2"></i><%= t '.login' %>
<% end %>
</li>
<% end %>
</ul>
<%= form_with url: athletes_path, method: :get, class: 'my-3', role: 'search' do |f| %>
<div class="input-group">
<%= f.text_field :q, type: 'search', class: 'form-control', placeholder: t('.name_or_id'), 'aria-label' => 'Search', autocomplete: 'off' %>
<%= f.submit t('.search'), class: 'btn btn-outline-light' %>
</div>
<% end %>
</div>
</div>
</div>
</nav>