8000 Remove all duplicate queries by sshane · Pull Request #503 · commaai/new-connect · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove all duplicate queries #503

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

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft

Conversation

sshane
Copy link
Contributor
@sshane sshane commented Apr 5, 2025

Idea is to selectively import setters/getters where this global state is needed.

As noted here, where we query the routes is quite far away from the RouteActivity, so we'd need to pass setters/getters as properties from multiple components to get this information which is cumbersome.

Instead we can either implement currentX signals, or a global store of the devices and routes we've loaded so far. Currently experimenting with which is simpler.

  • How do we set the currentRoute when you open a URL to a route without clicking? I'm sure Sam knows

Copy link
github-actions bot commented Apr 5, 2025

Changes:

path lines diff
./pages/dashboard/components/RouteList.tsx 162 +11
./store.tsx 6 +6
./pages/dashboard/components/DeviceList.tsx 47 +2
./components/RouteVideoPlayer.tsx 187 -1
./components/RouteActions.tsx 124 -1
./components/RouteStaticMap.tsx 66 -1
./pages/dashboard/Dashboard.tsx 157 -2
./components/RouteUploadButtons.tsx 105 -2
./pages/dashboard/activities/DeviceActivity.tsx 179 -4
./pages/dashboard/activities/RouteActivity.tsx 88 -8

Total lines: 4564 (0)

Copy link
github-actions bot commented Apr 5, 2025

deployed preview: https://503.connect-d5y.pages.dev

Welcome to connect! Make sure to:

  • read the contributing guidelines
  • mark your PR as a draft until it's ready to review
  • post the preview on Discord; feedback from users will speedup the PR review

Mobile

Desktop

@sshane sshane changed the title Instant route data loading Remove duplicate queries Apr 5, 2025
Comment on lines 88 to 103
<RouteActions route={currentRoute()} />
</div>
</div>

<div class="flex flex-col gap-2">
<span class="text-label-md uppercase">Upload Files</span>
<div class="flex flex-col rounded-md overflow-hidden bg-surface-container">
<RouteUploadButtons route={route()} />
<RouteUploadButtons route={currentRoute()} />
</div>
</div>

<div class="flex flex-col gap-2">
<span class="text-label-md uppercase">Route Map</span>
<div class="aspect-square overflow-hidden rounded-lg">
<Suspense fallback={<div class="h-full w-full skeleton-loader bg-surface-container" />}>
<RouteStaticMap route={route()} />
<RouteStaticMap route={currentRoute()} />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@greatgitsby have any thoughts about this? Passing in global signal from higher up, or just let each child component import the signal as needed? Not sure what's the more common pattern in web dev

Copy link
Contributor
@greatgitsby greatgitsby Apr 5, 2025

Choose a reason for hiding this comment

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

you're doing prop drilling which is one solution. the problem comes when you want to add more signals, you have to add more props, drill down further...

a Context abstracts all this away and you can reference whatever data you want whenever you need it. ends up being simpler to just call useAppContext() to get whatever you need

this app is pretty simple right now so you could get away with prop drilling, but as we add features, it might become a hindrance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was to get it working, I was thinking about just doing <RouteUploadButtons />, <RouteStaticMap /> and import the getter in each component as needed

Copy link
Contributor

Choose a reason for hiding this comment

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

oh interesting, i missed that you're creating global signal variables

i've always thought that global state is an antipattern in these types of programs, but if it solves the problem in less lines, it can always be refactored later

Copy link
Contributor

Choose a reason for hiding this comment

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

i also don't know how signals behave in a global context... we'd need to test this out

Copy link
Contributor Author
@sshane sshane Apr 5, 2025

Choose a reason for hiding this comment

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

https://www.solidjs.com/tutorial/stores_nocontext

Sometimes context is overkill, though; an alternative is to use the reactive system directly. For example, we can build a global reactive data store by creating a signal in a global scope, and exporting it for other modules to use

...

Solid's reactivity is a universal concept. It doesn't matter if it is inside or outside components. There is no separate concept for global vs local state.

@sshane sshane changed the title Remove duplicate queries Remove all duplicate queries Apr 5, 2025
@sshane
Copy link
Contributor Author
sshane commented Apr 5, 2025

We should be able to make a signal with all the loaded routes, then check once url state date string changes and set current route from that

@greatgitsby
Copy link
Contributor
greatgitsby commented Apr 5, 2025

check my draft PR; set an event on the route card click to setCurrentRoute, route is a prop

you don't even need to track all routes and do a lookup

@sshane
Copy link
Contributor Author
sshane commented Apr 5, 2025

This is for when you visit a URL to a route and don't click on the card

@incognitojam
Copy link
Collaborator

Partially implemented this in #579, but haven't tackled fetching the route or events

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.

3 participants
0