Repository navigation
Update markdown tabs - #130
Conversation
* have latest tab show in url as a query * update selected tab depending on url tab query
| const makeTextUrlFriendly = (val: string): string => | ||
| val.replace(/[^\w\-\._~]/g, '-').replace(/-+/g, '-') | ||
|
|
||
| const getUrlQueryVal = (query: string, param: string): string => { |
There was a problem hiding this comment.
Code still feels complex to me. Let know if you have suggestions for refactoring!
| const formattedVal = makeTextUrlFriendly(value) | ||
| const url = new URL(href) | ||
| url.searchParams.set(param, formattedVal) | ||
| window.history.pushState({}, '', url.href) |
There was a problem hiding this comment.
I tried navigate from gatsby and navigate from @reach/router but both would push the page to the top after updating the url. I also tried using this method but no change. The only way that I could find that kept the scroll position was using window.history.pushState. If you have an alternate way that is more "reacty", let me know :)
rogermparent
left a comment
There was a problem hiding this comment.
I had considered the possibility that an implementation based around a single Set or array keeping all the clicked tabs in order, adding or moving each clicked tab to the front, could be a possible way to simplify the implementation here.
Also, am I remembering correctly that this is supposed to preserve clicked tabs even when moving off the page and this works on dvc.org? It's not happening here:
tab-window-switch-demo.mp4
That doesn't happen on master either, just something I noticed, so this is still worth merging!
#123 has three tasks. This pull request finishes the first task. Keeping the query when you navigate to a different page is part of the third task. dvc.org currently does not have any of this implemented.
Good idea! I'll look into refactoring the code with this method! (Though this can probably be merged and refactored at a later date) |
Part of #123