Skip to content

feat(switch): add syncLevel for switch storage scopes#7222

Open
Eetwalt wants to merge 4 commits intomainfrom
persist-toggle-choice
Open

feat(switch): add syncLevel for switch storage scopes#7222
Eetwalt wants to merge 4 commits intomainfrom
persist-toggle-choice

Conversation

@Eetwalt
Copy link
Collaborator

@Eetwalt Eetwalt commented Mar 9, 2026

Summary

Add syncLevel property to Switch widget allowing to control the storage scope of toggle states:

  • site (default): shared across entire Liquipedia
  • wiki: shared within a single wiki
  • page: unique per page

How did you test this change?

dev + devtools

How to test

Toggle the swiches on a pages, check if switches on other pages are updated after refresh. Also check if the localStorage values are updated as intended.

https://liquipedia.net/rainbowsix/User:Eetwalt
https://liquipedia.net/leagueoflegends/User:Eetwalt
https://liquipedia.net/dota2/User:Eetwalt

@Eetwalt Eetwalt requested a review from a team as a code owner March 9, 2026 11:05
Copilot AI review requested due to automatic review settings March 9, 2026 11:05
@Eetwalt Eetwalt requested a review from a team as a code owner March 9, 2026 11:05
@Eetwalt Eetwalt added the javascript Changes to JavaScript files label Mar 9, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a syncLevel option to Switch toggle persistence so switch state can be stored at different localStorage scopes (site/wiki/page) via a new data-sync-level attribute consumed by the SwitchButtons JS module.

Changes:

  • Add syncLevel prop to the Lua Switch widget and emit it as data-sync-level.
  • Extend javascript/commons/SwitchButtons.js to read data-sync-level and build scope-specific localStorage keys (site/wiki/page).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
lua/wikis/commons/Widget/Switch.lua Introduces syncLevel prop (default site) and outputs data-sync-level on the toggle element.
javascript/commons/SwitchButtons.js Adds syncLevel to switchGroup state and updates localStorage key generation to respect site/wiki/page scope.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +17 to +21
local VALID_SYNC_LEVELS = {
'page',
'wiki',
'site',
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local VALID_SYNC_LEVELS = {
'page',
'wiki',
'site',
}
---@enum ValidSyncLevels
local VALID_SYNC_LEVELS = {
page = 'page',
wiki = 'wiki',
site = 'site',
}

imo SwitchSyncLevel would be a better name

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to SwitchSyncLevel as pascal case. Although there seems to be both naming conventions used for local vars, not sure which is better. pascal or upper snake

Copy link
Collaborator

@hjpalpha hjpalpha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm modulo the comment from eboy

buildLocalStorageKey: function ( groupName, syncLevel ) {
const base = 'LiquipediaSwitchButtons';

if ( syncLevel === 'site' ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use enums here too


buildLocalStorageKey: function () {
buildLocalStorageKey: function ( groupName, syncLevel ) {
const base = 'LiquipediaSwitchButtons';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to a high level so it's more visible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Changes to JavaScript files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants