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

Make the route loading more obvious. #260

Merged
merged 9 commits into from
Jul 12, 2023
Merged

Make the route loading more obvious. #260

merged 9 commits into from
Jul 12, 2023

Conversation

Pete-Y-CS
Copy link
Contributor

No description provided.

Peter York added 3 commits July 3, 2023 13:50
@Pete-Y-CS Pete-Y-CS changed the title Use externally defined progress bar and make the route loading more obvious. WIP: Use externally defined progress bar and make the route loading more obvious. Jul 5, 2023
@Pete-Y-CS Pete-Y-CS linked an issue Jul 5, 2023 that may be closed by this pull request
3 tasks
@@ -32,11 +32,12 @@ export class RouteTool {
) => void)[];
eventListenersFailure: (() => void)[];

constructor(map: Map, graphBytes: Uint8Array) {
constructor(map: Map, graphBytes: Uint8Array, deserialisedCallback=()=>{}) {
Copy link
Contributor

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

Copy link
Contributor

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

</script>

{#if !routeTool}
{#if !routeToolReady}
<!-- TODO the text should be fixed, and the progress bar float -->
Copy link
Contributor

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

<!-- 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} />
Copy link
Contributor

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

export let routeTool: RouteTool;
export let eventHandler: EventHandler;

let progress: Array<number> = [0 ];
Copy link
Contributor

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)

routeTool = new RouteTool($map, graphBytes);
const graphBytes = await fetchWithProgress(
url,
(percentLoaded) => (progress[0] = Math.min(percentLoaded, 90))
Copy link
Contributor

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

@@ -0,0 +1,52 @@
<script lang="ts">
Copy link
Contributor

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.

@Pete-Y-CS Pete-Y-CS force-pushed the progress-rebased branch 2 times, most recently from 57fd0ba to 75290fc Compare July 10, 2023 10:22
@robinlovelace-ate

This comment was marked as off-topic.

@Pete-Y-CS Pete-Y-CS changed the title WIP: Use externally defined progress bar and make the route loading more obvious. Make the route loading more obvious. Jul 11, 2023
Copy link
Contributor

@dabreegster dabreegster left a 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

Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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>
Copy link
Contributor

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" />
Copy link
Contributor

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:

  1. Show a 0-100 progress bar while we're downloading, up to the Content-Length of the .gzip file
  2. 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)
  3. 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.

@Pete-Y-CS Pete-Y-CS merged commit 86e1514 into main Jul 12, 2023
2 checks passed
@Pete-Y-CS Pete-Y-CS deleted the progress-rebased branch July 12, 2023 09:30
dabreegster added a commit that referenced this pull request Jul 12, 2023
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.

Improve progress bars
3 participants