Skip to content
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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

rominail
Copy link
Contributor

For the multi facets js selection, record user choice in local storage

@@ -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';
Copy link
Contributor

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);
Copy link
Contributor

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');
Copy link
Contributor

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;
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants