Skip to content
Snippets Groups Projects

Add dark mode toggle button

Merged Teal requested to merge light-switch into main
3 files
+ 108
5
Compare changes
  • Side-by-side
  • Inline
Files
3
class UsersController < ApplicationController
before_action :authenticate_user!, only: [ :update_theme ]
def leaderboard
@workload_data = User.leaderboard
end
def update_theme
if current_user.present?
# Ensure darkmode parameter is valid (light, dark)
theme = params[:darkmode].to_s
if [ "light", "dark" ].include?(theme)
if current_user.update(darkmode: theme)
render json: { success: true, theme: theme }, status: :ok
else
render json: { success: false, errors: current_user.errors.full_messages }, status: :unprocessable_entity
end
else
render json: { success: false, error: "Invalid theme value" }, status: :bad_request
end
else
render json: { success: false, error: "User not authenticated" }, status: :unauthorized
end
end
end
Loading