-
Notifications
You must be signed in to change notification settings - Fork 82
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
Updating browser history integration with the navigation Table of Contents (ToC) filter #847
base: develop
Are you sure you want to change the base?
Changes from 27 commits
527e520
4a4b00a
e8b38ca
9891727
4b894c8
6cd0f27
c279c07
61a3421
7015309
d7c6326
d7ae230
ab763d5
903687d
d1d6045
6455c37
37e82d8
25597c2
bb03df0
31df512
4217eb0
df406a8
be4c1ed
e7dcf6e
b295d9e
bfb7973
cdc9887
33f9178
e1b0a16
4ec2073
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -38,6 +38,7 @@ | |||||||||||||||||||||
<script> | ||||||||||||||||||||||
|
||||||||||||||||||||||
import throttle from 'lodash/throttle'; | ||||||||||||||||||||||
import debounce from 'lodash/debounce'; | ||||||||||||||||||||||
import NavSectionList from './NavSectionList'; | ||||||||||||||||||||||
import { termList, matches } from '~/common/DocsFilter/utils'; | ||||||||||||||||||||||
import tableOfContents from '~/tableOfContents.js'; | ||||||||||||||||||||||
|
@@ -51,6 +52,7 @@ | |||||||||||||||||||||
return { | ||||||||||||||||||||||
filterText: '', | ||||||||||||||||||||||
loaded: false, | ||||||||||||||||||||||
debounceUpdateQuery: null, | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
computed: { | ||||||||||||||||||||||
|
@@ -77,22 +79,54 @@ | |||||||||||||||||||||
return toc; | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
|
||||||||||||||||||||||
watch: { | ||||||||||||||||||||||
filterText(newValue) { | ||||||||||||||||||||||
if (window) { | ||||||||||||||||||||||
window.sessionStorage.setItem('nav-filter', newValue); | ||||||||||||||||||||||
//Clear the filter query when filtertext is empty | ||||||||||||||||||||||
if (!newValue) { | ||||||||||||||||||||||
this.$router.replace({ path: this.$route.path, query: {} }); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can just push the new route, instead of replacing it. |
||||||||||||||||||||||
} else { | ||||||||||||||||||||||
//else ,update the filter query param | ||||||||||||||||||||||
this.$router.push({ | ||||||||||||||||||||||
path: this.$route.path, | ||||||||||||||||||||||
query: { ...this.$route.query, filter: newValue }, | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
this.debouncedUpdateQuery(newValue); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you took another approach with the popstate listener, lets just remove this
Suggested change
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
mounted() { | ||||||||||||||||||||||
if (window) { | ||||||||||||||||||||||
const filterText = window.sessionStorage.getItem('nav-filter'); | ||||||||||||||||||||||
if (filterText) { | ||||||||||||||||||||||
this.filterText = filterText; | ||||||||||||||||||||||
const { filter } = this.$route.query; | ||||||||||||||||||||||
// Set filterText from the query parameter if it exists | ||||||||||||||||||||||
if (filter) { | ||||||||||||||||||||||
this.filterText = filter; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
this.$refs.links.scrollTop = window.sessionStorage.getItem('nav-scroll'); | ||||||||||||||||||||||
// Restoring filter state when a user navigates back | ||||||||||||||||||||||
window.addEventListener('popstate', event => { | ||||||||||||||||||||||
if (event.state && 'filterText' in event.state) { | ||||||||||||||||||||||
this.filterText = event.state.filterText; | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
this.filterText = ''; // Reset if no filterText is in state | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
// Create debounced function for updating the query | ||||||||||||||||||||||
this.debouncedUpdateQuery = debounce(newValue => { | ||||||||||||||||||||||
if (newValue) { | ||||||||||||||||||||||
this.$router.push({ | ||||||||||||||||||||||
path: this.$route.path, | ||||||||||||||||||||||
query: { ...this.$route.query, filter: newValue }, | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
this.$router.push({ path: this.$route.path, query: {} }); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}, 2000); // 2-second debounce delay | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we wont be using this debouncedUpdateQuery anymore, we can just remove these lines.
Suggested change
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
// don't show the nav until the state is set | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Don't show the nav until the state is set | ||||||||||||||||||||||
this.loaded = true; | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
methods: { | ||||||||||||||||||||||
|
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.
And dont forget to remove this data variable too :)
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.
Hi @RONAK-AI647! We are not using this state anymore, we can remove it too :)
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.
ahh I saw that , yet i missed , my bad !!!!!!