@@ -2,26 +2,47 @@ import { ErrorBoundary, JSXElement, Resource, Show, Suspense } from "solid-js";
22import { createErrorMessage } from "../../utils/misc" ;
33import * as Notifications from "../../elements/notifications" ;
44import { Conditional } from "./Conditional" ;
5+ import { LoadingStore } from "../../signals/util/loadingStore" ;
56
67export default function AsyncContent < T > (
78 props : {
8- resource : Resource < T | undefined > ;
99 errorMessage ?: string ;
1010 } & (
1111 | {
12- alwaysShowContent ?: never ;
13- children : ( data : T ) => JSXElement ;
12+ resource : Resource < T | undefined > ;
13+ loadingStore ?: never ;
1414 }
1515 | {
16- alwaysShowContent : true ;
17- showLoader ?: true ;
18- children : ( data : T | undefined ) => JSXElement ;
16+ loadingStore : LoadingStore < T | undefined > ;
17+ resource ?: never ;
1918 }
20- ) ,
19+ ) &
20+ (
21+ | {
22+ alwaysShowContent ?: never ;
23+ children : ( data : T ) => JSXElement ;
24+ }
25+ | {
26+ alwaysShowContent : true ;
27+ showLoader ?: true ;
28+ children : ( data : T | undefined ) => JSXElement ;
29+ }
30+ ) ,
2131) : JSXElement {
32+ const source =
33+ props . resource !== undefined
34+ ? {
35+ value : ( ) => props . resource ( ) ,
36+ loading : ( ) => props . resource . loading ,
37+ }
38+ : {
39+ value : ( ) => props . loadingStore . store ,
40+ loading : ( ) => props . loadingStore . state ( ) . loading ,
41+ } ;
42+
2243 const value = ( ) => {
2344 try {
24- return props . resource ( ) ;
45+ return source . value ( ) ;
2546 } catch ( err ) {
2647 const message = createErrorMessage (
2748 err ,
@@ -47,7 +68,7 @@ export default function AsyncContent<T>(
4768 } ;
4869 return (
4970 < >
50- < Show when = { p . showLoader && props . resource . loading } >
71+ < Show when = { p . showLoader && source . loading ( ) } >
5172 < div class = "preloader" >
5273 < i class = "fas fa-fw fa-spin fa-circle-notch" > </ i >
5374 </ div >
@@ -68,9 +89,9 @@ export default function AsyncContent<T>(
6889 }
6990 >
7091 < Show
71- when = { props . resource ( ) !== null && props . resource ( ) !== undefined }
92+ when = { source . value ( ) !== null && source . value ( ) !== undefined }
7293 >
73- { props . children ( props . resource ( ) as T ) }
94+ { props . children ( source . value ( ) as T ) }
7495 </ Show >
7596 </ Suspense >
7697 </ ErrorBoundary >
0 commit comments