-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi facet selection - Record last user state #4109
base: dev
Are you sure you want to change the base?
Conversation
@@ -140,6 +140,7 @@ VuFind.register('multiFacetsSelection', function multiFacetsSelection() { | |||
const activation_event = 'facet-selection-begin'; | |||
const deactivation_event = 'facet-selection-cancel'; | |||
const apply_event = 'facet-selection-done'; | |||
const localStorageVariableName = 'multiFacetsSelection'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other consts are in snake_case
@@ -313,6 +318,7 @@ VuFind.register('multiFacetsSelection', function multiFacetsSelection() { | |||
toggleSelectedFacetStyle(elem); | |||
} | |||
} | |||
saveUserSelectionLastState(isMultiFacetsSelectionActivated); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it doesn't hurt here, I think the proper place for this is inside the if (typeof enable !== 'undefined') {
block above.
@@ -338,6 +344,7 @@ VuFind.register('multiFacetsSelection', function multiFacetsSelection() { | |||
const activationElem = context.querySelector('.js-user-selection-multi-filters'); | |||
if (activationElem) { | |||
activationElem.addEventListener('change', function multiFacetSelectionChange() { toggleMultiFacetsSelection(this.checked); } ); | |||
toggleMultiFacetsSelection(localStorage.getItem(localStorageVariableName) === 'true'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there's saveUserSelectionLastState
, there should also be getUserSelectionLastState
or such to retrieve the selected state (as a boolean).
function saveUserSelectionLastState(state) { | ||
localStorage.setItem(localStorageVariableName, state); | ||
} | ||
|
||
function toggleMultiFacetsSelection(enable) { | ||
if (typeof enable !== 'undefined') { | ||
isMultiFacetsSelectionActivated = enable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to return early here if enable === isMultiFacetsSelectionActivated
. Otherwise on initialization this function can run with enable === false
without any previous activation and do useless work and emit an event that doesn't reflect reality.
For the multi facets js selection, record user choice in local storage