-
Notifications
You must be signed in to change notification settings - Fork 4
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
Make the route loading more obvious. #260
Conversation
Needs error handling and much more TS safety, but it initially works
src/lib/draw/route/route_tool.ts
Outdated
@@ -32,11 +32,12 @@ export class RouteTool { | |||
) => void)[]; | |||
eventListenersFailure: (() => void)[]; | |||
|
|||
constructor(map: Map, graphBytes: Uint8Array) { | |||
constructor(map: Map, graphBytes: Uint8Array, deserialisedCallback=()=>{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has only one caller, who sets the callback, so a default value seems odd. How about we just write the type? : () => void
src/style/main.css
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidentally added these files from the other branch, please remove from this PR
src/lib/draw/route/RouteMode.svelte
Outdated
</script> | ||
|
||
{#if !routeTool} | ||
{#if !routeToolReady} | ||
<!-- TODO the text should be fixed, and the progress bar float --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment becomes out of date with this PR
src/lib/draw/route/RouteMode.svelte
Outdated
<!-- TODO the text should be fixed, and the progress bar float --> | ||
<div bind:this={progress}>Route tool loading...</div> | ||
<p>Route tool loading</p> | ||
<ProgressBar bind:series={progress} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how this new dependency helps us. It can draw lots of fancier progress bars, but we just want a simple linear one. In the spirit of keeping dependencies low, shouldn't we avoid it? We could maybe replace the older CSS hacks with https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress
src/lib/draw/route/RouteMode.svelte
Outdated
export let routeTool: RouteTool; | ||
export let eventHandler: EventHandler; | ||
|
||
let progress: Array<number> = [0 ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this an array with just one element?
(also, npm run fmt
shows a diff here and elsewhere)
src/lib/draw/route/RouteMode.svelte
Outdated
routeTool = new RouteTool($map, graphBytes); | ||
const graphBytes = await fetchWithProgress( | ||
url, | ||
(percentLoaded) => (progress[0] = Math.min(percentLoaded, 90)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So here's where we say "we got all of Content-Length, cap at 90". This is subtle / unintuitive, so definitely worth a comment
src/lib/FetchProgressBar.svelte
Outdated
@@ -0,0 +1,52 @@ | |||
<script lang="ts"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks unused. Is the intention to keep this or the one in RouteMode
? I'd vote for having the progress bar logic wrapped up in its own component, not in the middle of RouteMode. Especially since we may want to use this for route info (worker.ts
) in some form in the future.
57fd0ba
to
75290fc
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
75290fc
to
acdf41b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me, after fixing the 2 requested changes!
A future idea is to extract the fetch logic and all the error / loading / done states into some kind of dedicated Svelte component. It could be agnostic to what's being loaded, except for understanding this Content-Length + gzip + extra unpack complication. Will probably need a bunch of callback plumbing, so not really important now
package-lock.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we revert the changes here please? Guessing this was a rebase problem. Without changes to package.json, I wouldn't expect the lock file to change generally
@@ -61,11 +68,58 @@ | |||
changeMode | |||
); | |||
}); | |||
|
|||
async function fetchWithProgress(url, setProgress: (number) => void) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async function fetchWithProgress(url, setProgress: (number) => void) { | |
// setProgress will generally be called with a number between 0 and 100, but it may exceed this for gzipped files. | |
// The server must send back a Content-Length header. | |
async function fetchWithProgress(url: string, setProgress: (number) => void) { |
<!-- TODO the text should be fixed, and the progress bar float --> | ||
<div bind:this={progress}>Route tool loading...</div> | ||
{#if !routeToolReady && !failedToLoadRouteTool && !downloadComplete} | ||
<label for="route-loading">Route tool loading</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elsewhere we've been doing <label>Route tool loading <progress value={progress} />
, the second form mentioned by https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label, to avoid making up an ID. Not too opinionated about it here
<progress id="route-loading" value={progress} /> | ||
{:else if downloadComplete && !routeToolReady && !failedToLoadRouteTool} | ||
<label for="route-unpacking">Route data unpacking</label> | ||
<progress id="route-unpacking" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the default animation of bouncing back and forth!
So the strategy is:
- Show a 0-100 progress bar while we're downloading, up to the Content-Length of the .gzip file
- We'll exceed 100%, because the browser is unpacking and passing along more than that Content-Length (and we have no way of knowing the uncompressed size, unless we store and send back a second header somehow)
- As soon as we hit 100%, we switch to the bouncey animation and say unpacking. We might still be loading from the network for some of this, but it's fine.
No description provided.