<p></p>
<p><b>@tomhughes</b> commented on this pull request.</p>

<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6492#discussion_r2491417075">app/views/layouts/_head.html.erb</a>:</p>
<pre style='color:#555'>> @@ -3,7 +3,7 @@
   <%= javascript_include_tag "turbo", :type => "module" %>
   <%= javascript_include_tag "application" %>
   <%= javascript_include_tag "i18n/#{I18n.locale}" %>
-  <% if preferred_color_scheme(:site) == "auto" %>
+  <% if preferred_color_scheme(:site).nil? %>
</pre>
<p dir="auto">If you reversed the branches here then you wouldn't need the <code class="notranslate">.nil?</code> which might be a bit clearer?</p>

<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6492#discussion_r2491434110">app/views/preferences/basic_preferences/show.html.erb</a>:</p>
<pre style='color:#555'>>                     :class => "form-select" %>
   </div>
 
   <div class="mb-3">
     <%= label_tag "map_color_scheme", t(".preferred_map_color_scheme"), :class => "form-label" %>
     <%= select_tag "map_color_scheme",
                    options_for_select(%w[auto light dark].map { |scheme| [t(".map_color_schemes.#{scheme}"), scheme] },
-                                      preferred_color_scheme(:map)),
+                                      current_user.preferences.find_by(:k => "map.color_scheme")&.v || "auto"),
</pre>
<p dir="auto">This seems like a step backwards but see my suggestion for changes to <code class="notranslate">preferred_color_scheme</code> for how we might avoid it.</p>

<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6492#discussion_r2491438722">app/controllers/application_controller.rb</a>:</p>
<pre style='color:#555'>> @@ -275,11 +275,12 @@ def preferred_editor
   end
 
   def preferred_color_scheme(subject)
-    if current_user
-      current_user.preferences.find_by(:k => "#{subject}.color_scheme")&.v || "auto"
-    else
-      "auto"
-    end
+    scheme = current_user ? current_user.preferences.find_by(:k => "#{subject}.color_scheme")&.v : nil
</pre>
<p dir="auto">Can this not use safe navigation like this?</p>
⬇️ Suggested change
<pre style="color: #555">-    scheme = current_user ? current_user.preferences.find_by(:k => "#{subject}.color_scheme")&.v : nil
+    scheme = current_user&.preferences.find_by(:k => "#{subject}.color_scheme")&.v
</pre>


<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6492#discussion_r2491454773">app/controllers/application_controller.rb</a>:</p>
<pre style='color:#555'>> @@ -275,11 +275,12 @@ def preferred_editor
   end
 
   def preferred_color_scheme(subject)
</pre>
<p dir="auto">I think that rather than taking a single subject here and then having to special case <code class="notranslate">:site</code> when deciding whether to fallback this could take <code class="notranslate">*subjects</code> and then try each one in turn until it finds one that is set to something other that <code class="notranslate">auto</code>.</p>
<p dir="auto">Then you could do a call like <code class="notranslate">preferred_color_scheme(:map, :site)</code> when you want fallback or <code class="notranslate">preferred_color_scheme(:map)</code> when you don't?</p>
<p dir="auto">Possibly it could also take a default value to return as a last resort instead of <code class="notranslate">nil</code> but that would probably need a keyword argument so it might be easier to stick with <code class="notranslate">||</code> at the call site unless we just go back to returning <code class="notranslate">auto</code> in that case.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/6492#pullrequestreview-3417754672">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLMBGL2S574M4ERSVU333DPFXAVCNFSM6AAAAACK54KIVGVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTIMJXG42TINRXGI">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLJLUABKY3OYHQMDBXD33DPFXA5CNFSM6AAAAACK54KIVGWGG33NNVSW45C7OR4XAZNRKB2WY3CSMVYXKZLTORJGK5TJMV32UY3PNVWWK3TUL5UWJTWLW3GDA.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/6492/review/3417754672</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/6492#pullrequestreview-3417754672",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/6492#pullrequestreview-3417754672",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>