@@ -3,7 +3,12 @@ import {type ComponentType, type ReactNode, useEffect, useState} from 'react'
3
3
import { combineLatest , of } from 'rxjs'
4
4
import { catchError , map } from 'rxjs/operators'
5
5
6
- import { ConfigResolutionError , type Source , type Workspace } from '../../config'
6
+ import {
7
+ ConfigResolutionError ,
8
+ type Source ,
9
+ type Workspace ,
10
+ type WorkspaceSummary ,
11
+ } from '../../config'
7
12
import { useActiveWorkspace } from '../activeWorkspaceMatcher'
8
13
import { SourceProvider } from '../source'
9
14
import { WorkspaceProvider } from '../workspace'
@@ -18,14 +23,13 @@ interface WorkspaceLoaderProps {
18
23
LoadingComponent : ComponentType
19
24
}
20
25
21
- function WorkspaceLoader ( {
22
- children ,
23
- LoadingComponent ,
24
- } : Omit < WorkspaceLoaderProps , 'ConfigErrorsComponent' > ) {
26
+ /**
27
+ * @internal
28
+ */
29
+ export function useWorkspaceLoader ( activeWorkspace : WorkspaceSummary ) {
25
30
const [ error , handleError ] = useState < unknown > ( null )
26
31
if ( error ) throw error
27
32
28
- const { activeWorkspace} = useActiveWorkspace ( )
29
33
const [ workspace , setWorkspace ] = useState < Workspace | null > ( null )
30
34
31
35
useEffect ( ( ) => {
@@ -69,6 +73,15 @@ function WorkspaceLoader({
69
73
return ( ) => subscription . unsubscribe ( )
70
74
} , [ activeWorkspace ] )
71
75
76
+ return workspace
77
+ }
78
+
79
+ function WorkspaceLoader ( {
80
+ children,
81
+ LoadingComponent,
82
+ } : Omit < WorkspaceLoaderProps , 'ConfigErrorsComponent' > ) {
83
+ const { activeWorkspace} = useActiveWorkspace ( )
84
+ const workspace = useWorkspaceLoader ( activeWorkspace )
72
85
if ( ! workspace ) return < LoadingComponent />
73
86
74
87
// TODO: may need a screen if one of the sources is not logged in. e.g. it
@@ -90,6 +103,9 @@ function WorkspaceLoader({
90
103
)
91
104
}
92
105
106
+ /**
107
+ * @internal
108
+ */
93
109
function WorkspaceLoaderBoundary ( { ConfigErrorsComponent, ...props } : WorkspaceLoaderProps ) {
94
110
const [ { error} , setError ] = useState < { error : unknown } > ( { error : null } )
95
111
0 commit comments