@@ -69,13 +69,8 @@ const UnstyledStreamPreview: FunctionComponent<StreamPreviewPros> = ({
69
69
)
70
70
const [ partition , setPartition ] = useState < number > ( activePartition )
71
71
const [ loading , setIsLoading ] = useState < boolean > ( )
72
- const [ stream , setStream ] = useState < Stream > ( )
73
- const { partitions } = stream ?. getMetadata ( ) || { }
74
- const partitionOptions = useMemo (
75
- ( ) =>
76
- partitions ? [ ...new Array ( partitions ) ] . map ( ( _ , index ) => index ) : undefined ,
77
- [ partitions ] ,
78
- )
72
+ const [ _ , setStream ] = useState < Stream > ( )
73
+ const [ partitions , setPartitions ] = useState < number > ( )
79
74
const streamData = useStreamData ( selectedStreamId , {
80
75
tail : 20 ,
81
76
partition,
@@ -85,14 +80,26 @@ const UnstyledStreamPreview: FunctionComponent<StreamPreviewPros> = ({
85
80
const loadStreamData = async ( ) => {
86
81
if ( client ) {
87
82
setIsLoading ( true )
88
- const result = await client . getStream ( selectedStreamId )
89
- setIsLoading ( false )
90
- setStream ( result )
83
+ try {
84
+ const result = await client . getStream ( selectedStreamId )
85
+ setStream ( result )
86
+ const metadata = await result . getMetadata ( )
87
+ const partitionCount = metadata . partitions as number
88
+ setPartitions ( partitionCount )
89
+ } finally {
90
+ setIsLoading ( false )
91
+ }
91
92
}
92
93
}
93
94
loadStreamData ( )
94
95
} , [ selectedStreamId , client ] )
95
96
97
+ const partitionOptions = useMemo (
98
+ ( ) =>
99
+ partitions ? [ ...new Array ( partitions ) ] . map ( ( _ , index ) => index ) : undefined ,
100
+ [ partitions ] ,
101
+ )
102
+
96
103
return (
97
104
< >
98
105
< LoadingIndicator loading = { loading } />
0 commit comments