Skip to content
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

Improve syntax lookup history behaviour #385

Closed
wants to merge 4 commits into from

Conversation

Minnozz
Copy link
Contributor

@Minnozz Minnozz commented Jun 10, 2021

(I based this PR on #387 because my development setup was not usable otherwise)

  • Use Next.Router.push instead of replace to allow the back button to work
  • Correctly link URL state to component state using a reducer with side-effects

Fixes #383

@Minnozz Minnozz changed the title Improve syntax lookup history behaviour [WIP] Improve syntax lookup history behaviour Jun 10, 2021
@Minnozz Minnozz marked this pull request as draft June 10, 2021 09:58
@Minnozz Minnozz changed the title [WIP] Improve syntax lookup history behaviour Improve syntax lookup history behaviour Jun 10, 2021
@Minnozz
Copy link
Contributor Author

Minnozz commented Jun 12, 2021

I was hesitant to add a dependency to this project, but I think this is the cleanest way to write this logic.

@Minnozz Minnozz marked this pull request as ready for review June 12, 2021 14:26
@ryyppy
Copy link
Member

ryyppy commented Jun 14, 2021

What makes the logic cleaner with ReactUpdate? It might look cleaner on first glance, but for me it's currently not entirely clear what benefits I get over the approach we had before?

Comment on lines -174 to -198
/*
This effect syncs the url anchor with the currently shown final match
within the fuzzy finder. If there is a new match that doesn't align with
the current anchor, the url will be rewritten with the correct anchor.

In case a selection got removed, it will also remove the anchor from the url.
We don't replace on every state change, because replacing the url is expensive
*/
React.useEffect1(() => {
switch (state, getAnchor(router.asPath)) {
| (ShowDetails(item), Some(anchor)) =>
let slug = GithubSlugger.slug(item.id)

if slug !== anchor {
router->Next.Router.replace("syntax-lookup#" ++ anchor)
} else {
()
}
| (ShowDetails(item), None) =>
router->Next.Router.replace("syntax-lookup#" ++ GithubSlugger.slug(item.id))
| (_, Some(_)) => router->Next.Router.replace("syntax-lookup")
| _ => ()
}
None
}, [state])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ryyppy For me, the improvement is being able to connect a specific action (like clearing the search box) to this effect (updating the URL). With ReactUpdate, you can queue the effect at the same location where you handle the action, whereas in the old version you have to compare the current URL and new state to reverse engineer what the most recent change was.

@Minnozz
Copy link
Contributor Author

Minnozz commented Jun 14, 2021

See inline comment: #385 (comment)

Of couse, what is clearer is subjective, and if you want I can try to achieve the same behaviour without this library.

@ryyppy
Copy link
Member

ryyppy commented Sep 10, 2021

@Minnozz Now that I had a closer look at rescript-react-update, I think your solution is valid, but for now I wanted to keep the dependency footprint low. #445 fixes the router problem (including a few other UX issues), so this should be fixed now.

Sorry for my late response times; I try to have a closer eye on open PRs now, in case you see potential improvements in the code.

@ryyppy ryyppy closed this Sep 10, 2021
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.

Back button behaviour in Syntax lookup
3 participants