Skip to content

Added persistence in window scope for filtering and tabs state. #921

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

Merged
merged 1 commit into from
Jun 3, 2020

Conversation

pikinier20
Copy link
Contributor

@@ -19,6 +19,11 @@ function initTabs(){
showCorrespondingTabBody(element)
element.addEventListener('click', (event) => toggleSections(event))
})
let cached = localStorage.getItem("active-tab")
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm that means that there is only one entry for all pages, so when i change tab on 1 page it will be the same on the others.

I don't think it should work like that. You can add a location to the end of the key to make it page-specific.

Same thing goes for the sourceset filters, but imho persisting them between pages i nice.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also you can just do if(cached) and why do you need to JSON.parse it when it is a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have spoken with @Kordyjan about scope of cache and if I understood correctly, we decided to make filters cache to work between pages.

About comparison - I never know how to check nulls and undefined's correctly.

About JSON.parse - It's true, I didn't realized that it is just string and my default behavior is to call JSON.parse when retrieving data from localStorage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed null-checks

if (cached !== null) {
let parsed = JSON.parse(cached)
filteringContext.activeFilters = filteringContext.restrictedDependencies
.filter(q => -1 == parsed.indexOf(q))
Copy link
Contributor

Choose a reason for hiding this comment

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

i find it weirdly disturbing to have a reversed equals XD

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

let cached = localStorage.getItem("active-tab")
if (cached !== null) {
let parsed = JSON.parse(cached)
document.querySelector("div[tabs-section] > button[data-togglable=" + parsed + "]").click()
Copy link
Contributor

Choose a reason for hiding this comment

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

Small thing but this will cause an error when on the first page we click on a tab and then move to another page that doesn't have this tab.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@MarcinAman MarcinAman self-requested a review June 3, 2020 10:12
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.

3 participants