Skip to content

Update markdown tabs - #130

Merged
casperdcl merged 1 commit into
masterfrom
update-tabs
Oct 26, 2021
Merged

casperdcl merged 1 commit into
masterfrom
update-tabs

Conversation

@julieg18

@julieg18 julieg18 commented Oct 21, 2021 •

Copy link
Copy Markdown
Contributor
  • have latest tab show in url as a query
  • update selected tab depending on url tab query

Part of #123

@shcheklein
shcheklein temporarily deployed to cml-dev-update-tabs-avpit5dxvd October 21, 2021 21:02 Inactive
@julieg18
julieg18 marked this pull request as draft October 21, 2021 21:02
* have latest tab show in url as a query
* update selected tab depending on url tab query
@julieg18
julieg18 temporarily deployed to cml-dev-update-tabs-avpit5dxvd October 21, 2021 21:07 Inactive
@julieg18
julieg18 marked this pull request as ready for review October 21, 2021 21:32
const makeTextUrlFriendly = (val: string): string =>
val.replace(/[^\w\-\._~]/g, '-').replace(/-+/g, '-')

const getUrlQueryVal = (query: string, param: string): string => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 rogermparent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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!

@julieg18

Copy link
Copy Markdown
Contributor Author

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:

#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.

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.

Good idea! I'll look into refactoring the code with this method! (Though this can probably be merged and refactored at a later date)

@casperdcl casperdcl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm, thx 🙏

@casperdcl casperdcl added enhancement New feature or request p1-important High priority A: website Area: website labels Oct 26, 2021
@casperdcl
casperdcl merged commit 32e1713 into master Oct 26, 2021
@casperdcl
casperdcl deleted the update-tabs branch October 26, 2021 13:05

This branch was previously deployed

1 inactive deployment
cml-dev-update-tabs-avpit5dxvd — c79c0367 Deployed Oct 21, 2021 by julieg18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A: website Area: website enhancement New feature or request p1-important High priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants