Skip to content

Commit 84b1b2a

Browse files
Merge pull request #161 from universal-ember/add-pending-state-to-page-component
Add `<:pending>` block to the `<Page>` component
2 parents 7efe4e5 + 0a49770 commit 84b1b2a

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

Diff for: docs-app/src/templates/page.gjs

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ function removeLoader() {
1010
export default Route(
1111
<template>
1212
<Page>
13+
<:pending>
14+
<div class="loading-page">
15+
Loading, compiling, etc
16+
</div>
17+
</:pending>
18+
1319
<:error as |error|>
1420
<div style="border: 1px solid red; padding: 1rem;" data-page-error>
1521
{{error}}
@@ -23,5 +29,14 @@ export default Route(
2329
</:success>
2430

2531
</Page>
32+
<style>
33+
.loading-page {
34+
position: fixed;
35+
top: 3rem;
36+
padding: 1rem;
37+
background: rgba(255, 255, 255, 0.8);
38+
color: black;
39+
}
40+
</style>
2641
</template>
2742
);

Diff for: src/browser/components/page.gts

+25
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ export class Page extends Component<{
2828
* ```
2929
*/
3030
error: [error: string];
31+
32+
/**
33+
* Before the document is compiled (or errored), this block will be active.
34+
*
35+
* Example:
36+
*
37+
* ```gjs
38+
* import { Page } from 'kolay/components';
39+
*
40+
* <template>
41+
* <Page>
42+
* <:pending>
43+
* Loading State
44+
* </:pending>
45+
* <:success></:success>
46+
* </Page>
47+
* </template>
48+
* ```
49+
*/
50+
pending: [];
51+
3152
/**
3253
* If compilation of the active page was successful, the `<:success>` black
3354
* will be active, and will pass the component reference to the caller.
@@ -56,6 +77,10 @@ export class Page extends Component<{
5677
{{yield this.selected.error to='error'}}
5778
{{/if}}
5879

80+
{{#if this.selected.isPending}}
81+
{{yield to='pending'}}
82+
{{/if}}
83+
5984
{{#if this.selected.prose}}
6085
{{yield this.selected.prose to='success'}}
6186
{{/if}}

Diff for: src/browser/services/kolay/selected.ts

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ export default class Selected extends Service {
7878
return this.proseCompiled.isReady;
7979
}
8080

81+
get isPending() {
82+
return !this.isReady;
83+
}
84+
8185
get hasError() {
8286
return Boolean(this.proseCompiled.error) || this.request.hasError;
8387
}

0 commit comments

Comments
 (0)