make regional leaderboards the default

This commit is contained in:
Echo 2025-06-18 15:41:46 -04:00
parent cd92d53eea
commit 6172c737e1
No known key found for this signature in database
9 changed files with 37 additions and 54 deletions

View file

@ -15,7 +15,7 @@ class LeaderboardsController < ApplicationController
private
def set_params
@use_timezone_leaderboard = current_user && Flipper.enabled?(:timezone_leaderboard, current_user)
@use_timezone_leaderboard = current_user&.default_timezone_leaderboard
@period_type = validated_period_type
@scope = params[:scope] || (@use_timezone_leaderboard ? "regional" : "global")
@scope_description = scope_description

View file

@ -85,10 +85,10 @@ class StaticPagesController < ApplicationController
end
def mini_leaderboard
@use_timezone_leaderboard = current_user && Flipper.enabled?(:timezone_leaderboard, current_user)
use_timezone_leaderboard = current_user&.default_timezone_leaderboard
if @use_timezone_leaderboard && current_user&.timezone_utc_offset
# Use regional leaderboard for beta participants
if use_timezone_leaderboard && current_user&.timezone_utc_offset
# we now doing it by default wooo
@leaderboard = LeaderboardGenerator.generate_timezone_offset_leaderboard(
Date.current, current_user.timezone_utc_offset, :daily
)

View file

@ -20,32 +20,6 @@ class UsersController < ApplicationController
end
def update
# Handle timezone leaderboard toggle
if params[:toggle_timezone_leaderboard] == "1"
if Flipper.enabled?(:timezone_leaderboard, @user)
Flipper.disable(:timezone_leaderboard, @user)
message = "Regional & Timezone Leaderboards disabled"
else
Flipper.enable(:timezone_leaderboard, @user)
message = "Regional & Timezone Leaderboards enabled"
end
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.replace(
"timezone_leaderboard_toggle",
partial: "timezone_leaderboard_toggle",
locals: { user: @user }
)
end
format.html do
redirect_to is_own_settings? ? my_settings_path : settings_user_path(@user),
notice: message
end
end
return
end
# Handle regular user settings updates
if params[:user].present?
if @user.update(user_params)
@ -132,6 +106,6 @@ class UsersController < ApplicationController
end
def user_params
params.require(:user).permit(:uses_slack_status, :hackatime_extension_text_type, :timezone, :allow_public_stats_lookup)
params.require(:user).permit(:uses_slack_status, :hackatime_extension_text_type, :timezone, :allow_public_stats_lookup, :default_timezone_leaderboard)
end
end

View file

@ -10,6 +10,7 @@ class User < ApplicationRecord
validates :country_code, inclusion: { in: ISO3166::Country.codes }, allow_nil: true
attribute :allow_public_stats_lookup, :boolean, default: true
attribute :default_timezone_leaderboard, :boolean, default: true
def country_name
ISO3166::Country.new(country_code).common_name

View file

@ -26,7 +26,7 @@
<div class="mini-leaderboard">
<p class="super">
<% if leaderboard.respond_to?(:scope_name) %>
🧪 <strong><%= link_to "Regional Leaderboard", my_settings_path(anchor: "user_beta_features") %>:</strong> Showing others in <%= link_to "your timezone", my_settings_path(anchor: "user_timezone") %>
<strong>Showing others in <%= link_to "your timezone", my_settings_path(anchor: "user_timezone") %>
<% else %>
This leaderboard is in <%= Leaderboard::GLOBAL_TIMEZONE %>.
<% if current_user && timezone_difference_in_seconds(Leaderboard::GLOBAL_TIMEZONE, current_user.timezone) != 0 %>

View file

@ -3,13 +3,13 @@
<h1>Leaderboard</h1>
<% if @scope == 'regional' %>
<em>🧪 <strong>Regional Leaderboard:</strong> Showing users in <%= @scope_description %></em>
<em><strong>Regional Leaderboard:</strong> Showing users in <%= @scope_description %></em>
<% elsif @scope == 'timezone' %>
<em>🧪 <strong>Timezone Leaderboard:</strong> Showing users in <%= @scope_description %></em>
<em><strong>Timezone Leaderboard:</strong> Showing users in <%= @scope_description %></em>
<% elsif @scope == 'global' %>
<em title="Current UTC time: <%= Time.now.utc.strftime('%H:%M:%S UTC') %>">This leaderboard runs in UTC time!</em>
<% else %>
<em>🧪 <strong>Regional Leaderboard:</strong> Showing users in <%= @scope_description %></em>
<em><strong>Regional Leaderboard:</strong> Showing users in <%= @scope_description %></em>
<% end %>
<div class="period-toggle">
@ -21,18 +21,14 @@
class: "period-toggle-btn #{@period_type == :last_7_days ? 'active' : ''}" %>
</div>
<% if current_user && Flipper.enabled?(:timezone_leaderboard, current_user) %>
<div class="period-toggle">
<%= link_to "Timezone", leaderboards_path(period_type: @period_type, scope: 'timezone'),
class: "period-toggle-btn #{@scope == 'timezone' ? 'active' : ''}" %>
<%= link_to "Regional", leaderboards_path(period_type: @period_type, scope: 'regional'),
class: "period-toggle-btn #{@scope == 'regional' ? 'active' : ''}" %>
<%= link_to "Global", leaderboards_path(period_type: @period_type, scope: 'global'),
class: "period-toggle-btn #{@scope == 'global' ? 'active' : ''}" %>
</div>
<% end %>
<div class="period-toggle">
<%= link_to "Timezone", leaderboards_path(period_type: @period_type, scope: 'timezone'),
class: "period-toggle-btn #{@scope == 'timezone' ? 'active' : ''}" %>
<%= link_to "Regional", leaderboards_path(period_type: @period_type, scope: 'regional'),
class: "period-toggle-btn #{@scope == 'regional' ? 'active' : ''}" %>
<%= link_to "Global", leaderboards_path(period_type: @period_type, scope: 'global'),
class: "period-toggle-btn #{@scope == 'global' ? 'active' : ''}" %>
</div>
<% if current_user && current_user.github_uid.blank? %>
<p>

View file

@ -4,9 +4,8 @@
<small>Access regional leaderboards that show users in your timezone region or specific timezone. Choose between timezone-specific, regional (UTC offset), or global competition modes.</small>
</p>
<%= form_with url: (@is_own_settings ? my_settings_path : settings_user_path(user)), method: :patch, local: false do |f| %>
<%= hidden_field_tag :toggle_timezone_leaderboard, "1" %>
<%= f.submit Flipper.enabled?(:timezone_leaderboard, user) ? "Disable Feature" : "Enable Feature",
role: "button",
class: Flipper.enabled?(:timezone_leaderboard, user) ? "secondary" : "" %>
<%= f.check_box :default_timezone_leaderboard, checked: user.default_timezone_leaderboard, id: "user_default_timezone_leaderboard" %>
<%= f.label :default_timezone_leaderboard, "Default to Timezone Leaderboard", for: "user_default_timezone_leaderboard" %>
<%= f.submit "Save", role: "button" %>
<% end %>
</div>

View file

@ -270,13 +270,21 @@
<article>
<header>
<h2 id="user_beta_features">🧪 Beta Features</h2>
<p>Enable experimental features and help us test new functionality.</p>
<h2 id="user_beta_features">🏆 Leaderboard settings</h2>
<p>Customize how you see the leaderboard</p>
</header>
<%= render "timezone_leaderboard_toggle", user: @user %>
</article>
<%#
<article>
<header>
<h2 id="user_beta_features">🧪 Beta Features</h2>
<p>Enable experimental features and help us test new functionality.</p>
</header>
</article>
%>
<% admin_tool do %>
<article>
<header>

View file

@ -0,0 +1,5 @@
class AddDefaultTimezoneLeaderboardToUsers < ActiveRecord::Migration[7.0]
def change
add_column :users, :default_timezone_leaderboard, :boolean, default: true, null: false
end
end