Setup navbar

This commit is contained in:
Max Wofford
2025-02-21 15:14:23 -05:00
parent c45e1e2f65
commit c41ae264e5
7 changed files with 61 additions and 20 deletions

View File

@@ -11,6 +11,8 @@
@import "https://uchu.style/color.css";
.avatar {
border-radius: 50%;
}
/* colors */
:root {
--primary-color: var(--uchu-red);
--muted-color: var(--uchu-gray);
}

View File

@@ -0,0 +1,7 @@
.nav-item.active {
color: var(--muted-color);
}
.nav-item.active {
color: var(--primary-color);
}

View File

@@ -1,4 +1,3 @@
.avatar {
border-radius: 50%;
}

View File

@@ -4,12 +4,14 @@ class StaticPagesController < ApplicationController
# get all unique project names
@project_names = current_user.project_names
@projects = current_user.projects
@current_project = current_user.active_project
@project_durations = @project_names.map do |project|
{
project: @projects.find { |p| p.project_key == project }&.label || project || "Unknown",
duration: current_user.heartbeats.where(project: project).duration_formatted
}
end
@current_project_duration = @project_durations.find { |p| p[:project] == @current_project }&.[](:duration)
end
end
end

View File

@@ -74,4 +74,14 @@ class User < ApplicationRecord
def project_names
heartbeats.select(:project).distinct.pluck(:project)
end
def active_project
heartbeats.order(time: :desc).first&.project
end
def active_project_duration
return nil unless active_project
Heartbeat.duration_formatted(heartbeats.where(project: active_project))
end
end

View File

@@ -23,22 +23,11 @@
</head>
<body>
<% flash.each do |name, msg| %>
<div class="flash-message <%= name %>">
<%= msg %>
</div>
<% end %>
<div class="header">
<% if current_user %>
<%= render "shared/user_mention", user: current_user %>
<%= link_to "Sign Out", signout_path, method: :delete, data: { "turbo-method": :delete } %>
<% else %>
<%= link_to "Sign in with Slack", slack_auth_path %>
<% end %>
</div>
<%= yield %>
<%= render "shared/nav" %>
<main style="margin-left: 250px; padding: 20px;">
<%= yield %>
</main>
<footer>
<div class="container">

View File

@@ -0,0 +1,32 @@
<aside>
<% flash.each do |name, msg| %>
<div class="flash-message <%= name %>">
<%= msg %>
</div>
<% end %>
<% if current_user %>
<%= render "shared/user_mention", user: current_user %>
<% if current_user.active_project %>
<div class="project-info">
<div>Currently working on: <%= current_user.active_project %></div>
<div>Duration: <%= current_user.active_project_duration %></div>
</div>
<% end %>
<%= link_to "Logout", signout_path, data: { turbo_method: :delete } %>
<% else %>
<%= link_to "Login", slack_auth_path %>
<% end %>
<ul>
<li>
<%= link_to root_path, class: "nav-item #{current_page?(root_path) ? 'active' : ''}" do %>
Home
<% end %>
</li>
<li>
<%= link_to leaderboards_path, class: "nav-item #{current_page?(leaderboards_path) ? 'active' : ''}" do %>
Leaderboards
<% end %>
</li>
</ul>
</aside>