Skip to content

Commit

Permalink
Now the theme is store dwith the user but also persists in the cookie…
Browse files Browse the repository at this point in the history
… if the user is logged out
  • Loading branch information
mlandauer committed Sep 13, 2023
1 parent 4e4ddd6 commit 99de25d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,49 @@ def show_tailwind_theme?
# the new theme to be shown even if you're logged out. The feature flag just enables the button
# that allows you to do the switching. Cookies are signed so the value can be manipulated by
# users outside of pushing the button
u = current_user
if u
r = show_tailwind_theme_user?
# Synchronise the cookie with what's stored with the user
update_tailwind_theme_cookie(r)
r
else
show_tailwind_theme_cookie?
end
end

sig { returns(T::Boolean) }
def show_tailwind_theme_cookie?
cookies.signed[:planningalerts_theme] == "tailwind"
end

sig { returns(T::Boolean) }
def show_tailwind_theme_user?
u = current_user
raise unless u

u.tailwind_theme
end

sig { params(tailwind: T::Boolean).void }
def update_tailwind_theme(tailwind)
update_tailwind_theme_cookie(tailwind)
update_tailwind_theme_user(tailwind)
end

sig { params(tailwind: T::Boolean).void }
def update_tailwind_theme_cookie(tailwind)
cookies.signed[:planningalerts_theme] = ("tailwind" if tailwind)
end

sig { params(tailwind: T::Boolean).void }
def update_tailwind_theme_user(tailwind)
u = current_user
return unless u

u.update!(tailwind_theme: tailwind)
end

sig { void }
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit(:name, :email, :password) }
Expand Down

0 comments on commit 99de25d

Please sign in to comment.