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

Move all router access to page-level components #712

Merged
merged 5 commits into from
Jul 12, 2023

Conversation

csillag
Copy link
Contributor

@csillag csillag commented Jul 11, 2023

We should only be accessing the URL (via the router) from page-level components, not individual components.
This improves the composability of the app.

Cleanup progress:

  • Paratime Dashboard
  • Token Dashboard
  • Account details
  • Other places

@github-actions
Copy link

github-actions bot commented Jul 11, 2023

Deployed to Cloudflare Pages

Latest commit: 45fbd64f6806bbc06a69791b4e15aa837c465897
Status:✅ Deploy successful!
Preview URL: https://1ad00afb.oasis-explorer.pages.dev

@csillag csillag changed the title Move all router access to page-level component Move all router access to page-level components Jul 11, 2023
@csillag csillag force-pushed the csillag/page-level-cleanup branch 4 times, most recently from ef72418 to 8dad915 Compare July 11, 2023 10:26
@csillag csillag marked this pull request as ready for review July 11, 2023 10:27
@csillag csillag requested review from lukaw3d and buberdds July 11, 2023 10:27
@csillag csillag force-pushed the csillag/page-level-cleanup branch 2 times, most recently from 25ba0c9 to b897412 Compare July 11, 2023 11:04
@csillag
Copy link
Contributor Author

csillag commented Jul 11, 2023

I think we should also move most data loading into the same page-level components in order to reduce redundancy in the code, but I will do that in a separate PR.

@csillag
Copy link
Contributor Author

csillag commented Jul 11, 2023

A technically interesting detail: we can also use our tabs (wrapping React Router's Outlet) to pass down some context, so we can also eliminate the repetitive loader configuration from the routes.


export const accountTransactionsContainerId = 'transactions'

export const AccountTransactionsCard: FC = () => {
const { scope, address } = useOutletContext<AccountDetailsContext>()
Copy link
Member

Choose a reason for hiding this comment

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

I don't actually see outlet context as better than getting things from URL. It looks less straightforward :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking was that this is part of hierarchical navigation; the outer part (the page) is containing the inner part (the tabs). Therefore if the outer part already go the data from the router, it's only fair that it passes it down to it's children. Doing this, we will be free to move the page wherever we want in the navigation tree, and the only thing we have to update is the top part.


On the other hand, one could also make the argument that since the tabs are references directly inside the routing tree definition, these are routing level components, on equal level as other page-level components, so they can talk to the router directly.

I'm happy to undo the outlet-based changes.

Copy link
Member

Choose a reason for hiding this comment

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

yep. I dont know

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lemme try out one more version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lukaw3d How about now? This time, all cards (both those that are embedded on the page + those that are used in tab menus) take props the same way, normally. The props are passed down from the menu, and received in the routes definition.

I think the actual components are very easy to read now. They don't have to interact with router, outlet, or anything. All the tricky parts are confined into the router itself, when we are already concentrating on building a menu.

@csillag csillag force-pushed the csillag/page-level-cleanup branch 2 times, most recently from 667ca20 to 1c9bccc Compare July 12, 2023 09:39
@@ -83,28 +83,23 @@ export const routes: RouteObject[] = [
children: [
{
path: '',
element: <AccountTransactionsCard />,
loader: addressParamLoader,
Component: () => <AccountTransactionsCard {...useAccountDetailsProps()} />,
Copy link
Member

Choose a reason for hiding this comment

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

This is nice. Hopefully react-router doesn't break it (this is v5 remnant)

@csillag csillag force-pushed the csillag/page-level-cleanup branch from 1c9bccc to 45fbd64 Compare July 12, 2023 11:33
@csillag csillag enabled auto-merge July 12, 2023 11:34
@csillag csillag merged commit 86167a5 into master Jul 12, 2023
6 checks passed
@csillag csillag deleted the csillag/page-level-cleanup branch July 12, 2023 11:35
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.

None yet

2 participants