-
Notifications
You must be signed in to change notification settings - Fork 87
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
Merged
AlexVelezLl
merged 29 commits into
learningequality:develop
from
RONAK-AI647:navigating-browser-history-issue
Jan 6, 2025
Merged
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
527e520
pushing to browser history
RONAK-AI647 4a4b00a
update index.vue
RONAK-AI647 e8b38ca
javascript check
RONAK-AI647 9891727
Restoring filter state when a user navigates back
RONAK-AI647 4b894c8
Update vue.index
RONAK-AI647 6cd0f27
javascript test
RONAK-AI647 c279c07
event to events
RONAK-AI647 61a3421
revert the commit
RONAK-AI647 7015309
Update index.vue
RONAK-AI647 d7c6326
from search to filter
RONAK-AI647 d7ae230
The URL perfecting
RONAK-AI647 ab763d5
Revert "The URL perfecting"
RONAK-AI647 903687d
Updating watch for URL fix
RONAK-AI647 d1d6045
Spacing and linting
RONAK-AI647 6455c37
lint-test
RONAK-AI647 37e82d8
Removing previous handlers
RONAK-AI647 25597c2
Pushing filter as query
RONAK-AI647 bb03df0
Adding debounceUpdate
RONAK-AI647 31df512
Adding debounce under mounted()
RONAK-AI647 4217eb0
Preserving the query when the button is clicked
RONAK-AI647 df406a8
Lint -fix (ubuntu version)
RONAK-AI647 be4c1ed
Force deploy
AlexVelezLl e7dcf6e
Updating Navlink.vue for preserving query param
RONAK-AI647 b295d9e
Update DocsLibraryLink.vue
RONAK-AI647 bfb7973
yarn lint-fix
RONAK-AI647 cdc9887
Merge branch 'navigating-browser-history-issue' of https://github.com…
RONAK-AI647 33f9178
Removing previous handler in index.vue
RONAK-AI647 e1b0a16
Removing debouncedUpdateQuery
RONAK-AI647 4ec2073
Update index.vue
RONAK-AI647 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,8 @@ | |
import NavSectionList from './NavSectionList'; | ||
import { termList, matches } from '~/common/DocsFilter/utils'; | ||
import tableOfContents from '~/tableOfContents.js'; | ||
|
||
import debounce from 'lodash/debounce'; | ||
|
||
export default { | ||
name: 'SideNav', | ||
components: { | ||
|
@@ -51,6 +52,7 @@ | |
return { | ||
filterText: '', | ||
loaded: false, | ||
debounceUpdateQuery: null, | ||
}; | ||
}, | ||
computed: { | ||
|
@@ -80,22 +82,62 @@ | |
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: {} }); | ||
} | ||
}, | ||
}, | ||
mounted() { | ||
if (window) { | ||
const filterText = window.sessionStorage.getItem('nav-filter'); | ||
if (filterText) { | ||
this.filterText = filterText; | ||
else { | ||
//else ,update the filter query param | ||
this.$router.push({ path: this.$route.path, query: { ...this.$route.query, filter: newValue}}); | ||
} | ||
this.debouncedUpdateQuery(newValue); | ||
} | ||
this.$refs.links.scrollTop = window.sessionStorage.getItem('nav-scroll'); | ||
} | ||
// don't show the nav until the state is set | ||
this.loaded = true; | ||
}, | ||
methods: { | ||
mounted() { | ||
if (window) { | ||
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 | ||
} | ||
|
||
// Modify navigation links to preserve the filter query | ||
this.$nextTick(() => { | ||
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 would suggest better update NavLink and DocsLibraryLink to pass the query params, so we have dont have to add an event listener to all links of the page :) |
||
this.$refs.links.querySelectorAll('a').forEach((link) => { | ||
link.addEventListener('click', (event) => { | ||
event.preventDefault(); | ||
const href = new URL(link.href); | ||
this.$router.push({ | ||
path: href.pathname, | ||
query: { ...this.$route.query } // Add existing query params to the new path | ||
}); | ||
}); | ||
}); | ||
}); | ||
// Don't show the nav until the state is set | ||
this.loaded = true; | ||
}, | ||
methods: { | ||
throttleHandleScroll: throttle(function handleScroll() { | ||
window.sessionStorage.setItem('nav-scroll', this.$refs.links.scrollTop); | ||
}, 100), | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 !!!!!!