Skip to content

Commit

Permalink
Add a loading interstitial
Browse files Browse the repository at this point in the history
  • Loading branch information
iftenney committed Dec 12, 2024
1 parent ce5d2b1 commit 7ed5d03
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 30 deletions.
17 changes: 17 additions & 0 deletions demo/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@
"footer footer";
}

#main-loading {
grid-area: left-bar / span 2;
align-self: center;
justify-self: center;
min-width: 50%;

padding: 16px;
border-radius: 6px;
border: 1px solid #ccc;
background: #e8e8e8;

h2 {
margin-top: 0;
margin-bottom: 8px;
}
}

md-icon.icon-button {
--md-icon-size: 16px;
}
Expand Down
43 changes: 29 additions & 14 deletions demo/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,18 @@ export class TDAApp extends MobxLitElement {
`;
}

renderLoading() {
if (this.mainDataLoaderService.isLoading == null) return null;

// prettier-ignore
return html`
<div id='main-loading'>
<h2>Loading data</h2>
${this.mainDataLoaderService.isLoading!}
</div>
`;
}

override render() {
const onExampleClick = (e: CustomEvent<ExampleClicked>) => {
const id = e.detail.id;
Expand All @@ -615,20 +627,23 @@ export class TDAApp extends MobxLitElement {
${this.renderDataFilters()}
${this.renderTaskFilters()}
</div>
<div id='left-bar'>
<tda-data-index .index=${this.filteredDataIndex}
selectedId=${this.selectedExId}
@example-clicked=${onExampleClick}>
</tda-data-index>
</div>
<div id="example-controls">
${this.renderExampleControls()}
</div>
<div id="example">
<tda-example-view .example=${this.currentExample}
.sxsExample=${this.sxsEnabled ? this.sxsExample : undefined}>
</tda-example-view>
</div>
${this.renderLoading() ??
html`
<div id='left-bar'>
<tda-data-index .index=${this.filteredDataIndex}
selectedId=${this.selectedExId}
@example-clicked=${onExampleClick}>
</tda-data-index>
</div>
<div id="example-controls">
${this.renderExampleControls()}
</div>
<div id="example">
<tda-example-view .example=${this.currentExample}
.sxsExample=${this.sxsEnabled ? this.sxsExample : undefined}>
</tda-example-view>
</div>`
}
<div id="footer">
${this.statusMessage}
</div>
Expand Down
4 changes: 4 additions & 0 deletions demo/data_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export class DataLoaderService {
@observable jsonlPath: string | null = null;
@observable examples: TDAExample[] = [];

@observable isLoading: string | null = null;

pathIsUploadedFile(path: string): boolean {
return path.startsWith('uploaded:');
}
Expand All @@ -81,6 +83,7 @@ export class DataLoaderService {
return;
}

this.isLoading = path;
if (this.pathIsUploadedFile(path)) {
this.examples = await uploadedFileManager.loadExamples(path);
}
Expand All @@ -89,6 +92,7 @@ export class DataLoaderService {
}

this.jsonlPath = path;
this.isLoading = null;
console.log(
`DataLoaderService: parsed ${this.examples.length} examples from ${this.jsonlPath}`,
);
Expand Down
62 changes: 48 additions & 14 deletions docs/demo/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/demo/bundle.js.map

Large diffs are not rendered by default.

0 comments on commit 7ed5d03

Please sign in to comment.