@@ -8,6 +8,13 @@ interface Stream {
88 contentType ?: string
99}
1010
11+ interface RegistryEvent {
12+ type : `created` | `deleted`
13+ path : string
14+ contentType ?: string
15+ timestamp : number
16+ }
17+
1118function RootLayout ( ) {
1219 const [ streams , setStreams ] = useState < Array < Stream > > ( [ ] )
1320 const [ newStreamPath , setNewStreamPath ] = useState ( `` )
@@ -36,40 +43,30 @@ function RootLayout() {
3643 } )
3744 }
3845
39- // Read all chunks from the registry
46+ // Read all events from the registry
4047 const loadedStreams : Array < Stream > = [ ]
4148
4249 try {
43- for await ( const chunk of registryStream . read ( { offset : `-1` } ) ) {
44- console . log ( `Registry chunk:` , chunk )
45- if ( chunk . data . length > 0 ) {
46- const text = new TextDecoder ( ) . decode ( chunk . data )
47- console . log ( `Registry text:` , text )
48- const lines = text . trim ( ) . split ( `\n` ) . filter ( Boolean )
49-
50- for ( const line of lines ) {
51- try {
52- const event = JSON . parse ( line )
53- console . log ( `Registry event:` , event )
54- if ( event . type === `created` ) {
55- loadedStreams . push ( {
56- path : event . path ,
57- contentType : event . contentType ,
58- } )
59- } else if ( event . type === `deleted` ) {
60- const index = loadedStreams . findIndex (
61- ( s ) => s . path === event . path
62- )
63- if ( index !== - 1 ) {
64- loadedStreams . splice ( index , 1 )
65- }
66- }
67- } catch ( e ) {
68- console . error ( `Error parsing registry line:` , line , e )
50+ for await ( const chunk of registryStream . json <
51+ RegistryEvent | Array < RegistryEvent >
52+ > ( ) ) {
53+ const events = Array . isArray ( chunk ) ? chunk : [ chunk ]
54+
55+ for ( const event of events ) {
56+ if ( event . type === `created` ) {
57+ loadedStreams . push ( {
58+ path : event . path ,
59+ contentType : event . contentType ,
60+ } )
61+ } else {
62+ const index = loadedStreams . findIndex (
63+ ( s ) => s . path === event . path
64+ )
65+ if ( index !== - 1 ) {
66+ loadedStreams . splice ( index , 1 )
6967 }
7068 }
7169 }
72- console . log ( `Loaded streams:` , loadedStreams )
7370 setStreams ( loadedStreams )
7471 }
7572 } catch ( readErr ) {
@@ -106,7 +103,7 @@ function RootLayout() {
106103 const deleteStream = async ( path : string ) => {
107104 if (
108105 ! window . confirm (
109- `Delete stream "${ path } "?\n\nThis action cannot be undone.`
106+ `Delete stream "${ decodeURIComponent ( path ) } "?\n\nThis action cannot be undone.`
110107 )
111108 ) {
112109 return
@@ -140,7 +137,7 @@ function RootLayout() {
140137 placeholder = "New stream path"
141138 value = { newStreamPath }
142139 onChange = { ( e ) => setNewStreamPath ( e . target . value ) }
143- onKeyPress = { ( e ) => e . key === `Enter` && void createStream ( ) }
140+ onKeyDown = { ( e ) => e . key === `Enter` && void createStream ( ) }
144141 />
145142 < select
146143 value = { newStreamContentType }
@@ -163,14 +160,16 @@ function RootLayout() {
163160 onClick = { ( ) => setSidebarOpen ( false ) }
164161 >
165162 < div >
166- < div className = "stream-path" > { stream . path } </ div >
163+ < div className = "stream-path" >
164+ { decodeURIComponent ( stream . path ) }
165+ </ div >
167166 < div className = "stream-type" >
168- { stream . contentType || `unknown` }
167+ { stream . contentType ?. toLowerCase ( ) || `unknown` }
169168 </ div >
170169 </ div >
171170 < button
172171 className = "delete-btn"
173- title = { `Delete stream: ${ stream . path } ` }
172+ title = { `Delete stream: ${ decodeURIComponent ( stream . path ) } ` }
174173 onClick = { ( e ) => {
175174 e . preventDefault ( )
176175 e . stopPropagation ( )
0 commit comments