Show current user name in site header
Assisted-by: Claude Opus 4.6 via pi
change xrtwqkvmqlostuvntxvpmlllvxvvqqrt
commit 3a9cda4ca54a001b86b534e032f7b3dbee6a6385
author Alpha Chen <alpha@kejadlen.dev>
date
parent pqusmnsx
diff --git a/lib/views/layout.rb b/lib/views/layout.rb
index cac52f5..2c3fa7f 100644
--- a/lib/views/layout.rb
+++ b/lib/views/layout.rb
@@ -4,7 +4,8 @@ require "phlex"
 
 module Views
   class Layout < Phlex::HTML
-    def initialize(title: "Ketchup")
+    def initialize(current_user:, title: "Ketchup")
+      @current_user = current_user
       @title = title
     end
 
@@ -19,7 +20,13 @@ module Views
           link(rel: "stylesheet", href: "/css/utopia.css")
           link(rel: "stylesheet", href: "/css/app.css")
         end
-        body(&)
+        body do
+          header(class: "site-header") do
+            span(class: "site-name") { "Ketchup" }
+            span(class: "user") { @current_user[:name] || @current_user[:login] }
+          end
+          yield
+        end
       end
     end
   end
diff --git a/lib/views/series/new.rb b/lib/views/series/new.rb
index 0506a35..299bb96 100644
--- a/lib/views/series/new.rb
+++ b/lib/views/series/new.rb
@@ -7,8 +7,12 @@ require_relative "../layout"
 module Views
   module Series
     class New < Phlex::HTML
+      def initialize(current_user:)
+        @current_user = current_user
+      end
+
       def view_template
-        render Layout.new(title: "New Series — Ketchup") do
+        render Layout.new(current_user: @current_user, title: "New Series — Ketchup") do
           div(class: "wrapper flow") do
             h1 { "New Series" }
 
diff --git a/lib/web.rb b/lib/web.rb
index c6955f9..7f5aca2 100644
--- a/lib/web.rb
+++ b/lib/web.rb
@@ -22,7 +22,7 @@ class Web < Roda
     r.halt 403 unless current_user
 
     r.root do
-      Views::Series::New.new.call
+      Views::Series::New.new(current_user:).call
     end
   end
 end
diff --git a/public/css/app.css b/public/css/app.css
index e12df09..9c61cf4 100644
--- a/public/css/app.css
+++ b/public/css/app.css
@@ -32,6 +32,27 @@ body {
 
 h1 { font-size: var(--step-3); }
 
+/* -------------------- */
+/* Site header */
+/* -------------------- */
+
+.site-header {
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+  padding: var(--space-xs) var(--grid-gutter);
+  border-block-end: 1px solid #e0e0e0;
+}
+
+.site-name {
+  font-weight: 700;
+}
+
+.user {
+  font-size: var(--step--1);
+  color: #666;
+}
+
 /* -------------------- */
 /* Page wrapper */
 /* -------------------- */
diff --git a/test/test_web.rb b/test/test_web.rb
index d101d86..a0eb8cd 100644
--- a/test/test_web.rb
+++ b/test/test_web.rb
@@ -17,6 +17,11 @@ class TestWeb < Minitest::Test
     assert_includes last_response.body, 'name="name"'
   end
 
+  def test_root_shows_current_user
+    get "/", {}, tailscale_headers(name: "Alice")
+    assert_includes last_response.body, "Alice"
+  end
+
   def test_root_requires_tailscale_user
     get "/"
     assert_equal 403, last_response.status
@@ -24,7 +29,11 @@ class TestWeb < Minitest::Test
 
   private
 
-  def tailscale_headers(login: "alice@example.com", name: "Alice", profile_pic: "https://example.com/alice.jpg")
+  def tailscale_headers(
+    login: "alice@example.com",
+    name: "Alice",
+    profile_pic: "https://example.com/alice.jpg"
+  )
     {
       "HTTP_TAILSCALE_USER_LOGIN" => login,
       "HTTP_TAILSCALE_USER_NAME" => name,