Skip to content

Commit

Permalink
Homogenize on COOKIE (vs: STORAGE_KEY, COOKIE_NAME)
Browse files Browse the repository at this point in the history
For consistency/searchability.
  • Loading branch information
pdobb committed Jan 28, 2025
1 parent 4d885bf commit b3fa0dc
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/controllers/games/new/custom_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create
if settings.valid?
Game::Current.(settings:, user: current_user) {
layout.store_http_cookie(
Games::New::Custom::Form::STORAGE_KEY,
Games::New::Custom::Form::COOKIE,
value: settings.to_json)
}

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/ui_portal/patterns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def edit_pattern_params

def store_pattern_settings(settings)
layout.store_http_cookie(
UIPortal::Patterns::New::SettingsForm::STORAGE_KEY,
UIPortal::Patterns::New::SettingsForm::COOKIE,
value: settings.to_json)
end

Expand Down
8 changes: 4 additions & 4 deletions app/javascript/controllers/theme_controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller } from "@hotwired/stimulus"

export default class ThemeController extends Controller {
static STORAGE_KEY = "theme"
static COOKIE = "theme"

static LIGHT_THEME = "light"
static LIGHT_THEME_COLOR = "#fff"
Expand Down Expand Up @@ -216,14 +216,14 @@ export default class ThemeController extends Controller {
}

get #theme() {
return localStorage.getItem(ThemeController.STORAGE_KEY)
return localStorage.getItem(ThemeController.COOKIE)
}

set #theme(value) {
if (value == ThemeController.SYSTEM_THEME) {
localStorage.removeItem(ThemeController.STORAGE_KEY)
localStorage.removeItem(ThemeController.COOKIE)
} else {
localStorage.setItem(ThemeController.STORAGE_KEY, value)
localStorage.setItem(ThemeController.COOKIE, value)
}
}
}
4 changes: 2 additions & 2 deletions app/views/games/current/rules/collapse_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

# Games::Current::Rules::CollapseContainer
class Games::Current::Rules::CollapseContainer
COOKIE_NAME = "rules"
COOKIE = "rules"

def initialize(context:)
@context = Context.new(context)
end

def cookie_name = COOKIE_NAME
def cookie_name = COOKIE

def button_id = @button_id ||= "rules_button-#{Time.new.to_i}"
def content_id = @content_id ||= "rules_content-#{Time.new.to_i}"
Expand Down
4 changes: 2 additions & 2 deletions app/views/games/new/custom/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Games::New::Custom::Form represents the "New Custom Game" form.
class Games::New::Custom::Form
STORAGE_KEY = :board_settings
COOKIE = :board_settings

def initialize(settings:, context:)
@settings = settings
Expand Down Expand Up @@ -39,7 +39,7 @@ def display_errors

def previous_settings
@previous_settings ||=
JSON.parse(cookies[STORAGE_KEY] || "{}").with_indifferent_access
JSON.parse(cookies[COOKIE] || "{}").with_indifferent_access
end

def cookies = context.cookies
Expand Down
4 changes: 2 additions & 2 deletions app/views/home/roster/slide_menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Home::Roster::SlideMenu represents the War Room Roster slide menu.
class Home::Roster::SlideMenu
COOKIE_NAME = "war_room-roster"
COOKIE = "war_room-roster"

def self.css
# rubocop:disable Layout/MultilineArrayLineBreaks
Expand Down Expand Up @@ -32,7 +32,7 @@ def initialize(context:)
@context = Context.new(context)
end

def cookie_name = COOKIE_NAME
def cookie_name = COOKIE

def title = "Roster"

Expand Down
4 changes: 2 additions & 2 deletions app/views/ui_portal/patterns/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def display_errors

# UIPortal::Patterns::New::SettingsForm
class SettingsForm
STORAGE_KEY = :pattern_settings
COOKIE = :pattern_settings

def initialize(pattern_settings, context:)
@pattern_settings = pattern_settings
Expand All @@ -55,7 +55,7 @@ def any_errors? = pattern_settings.errors.any?

def previous_settings
@previous_settings ||=
JSON.parse(cookies[STORAGE_KEY] || "{}").with_indifferent_access
JSON.parse(cookies[COOKIE] || "{}").with_indifferent_access
end

def cookies = context.cookies
Expand Down

0 comments on commit b3fa0dc

Please sign in to comment.