@@ -107,10 +107,7 @@ const createChatRecipe = handler<
107107 messages : [ ] ,
108108 expandChat : false ,
109109 content : "" ,
110- allCharms : [
111- ...allCharms . get ( ) ,
112- ...charmsList . get ( ) . map ( ( i ) => i . charm ) ,
113- ] as unknown as OpaqueRef < Cell < MentionableCharm [ ] > > , // TODO(bf): types...
110+ allCharms,
114111 } ) ;
115112 // store the charm ref in a cell (pass isInitialized to prevent recursive calls)
116113 return storeCharm ( { charm, selectedCharm, charmsList, isInitialized } ) ;
@@ -158,12 +155,25 @@ const handleCharmLinkClicked = handler(
158155 } ,
159156) ;
160157
158+ const combineLists = lift (
159+ (
160+ { allCharms, charmsList } : { allCharms : any [ ] ; charmsList : CharmEntry [ ] } ,
161+ ) => {
162+ return [ ...charmsList . map ( ( c ) => c . charm ) , ...allCharms ] ;
163+ } ,
164+ ) ;
165+
161166// create the named cell inside the recipe body, so we do it just once
162167export default recipe < Input , Output > (
163168 "Launcher" ,
164169 ( { selectedCharm, charmsList, allCharms } ) => {
165170 logCharmsList ( { charmsList } ) ;
166171
172+ const combined = combineLists ( {
173+ allCharms : allCharms as unknown as any [ ] ,
174+ charmsList,
175+ } ) ;
176+
167177 return {
168178 [ NAME ] : "Launcher" ,
169179 [ UI ] : (
@@ -173,7 +183,7 @@ export default recipe<Input, Output>(
173183 onClick = { createChatRecipe ( {
174184 selectedCharm,
175185 charmsList,
176- allCharms : allCharms as unknown as any ,
186+ allCharms : combined as unknown as any ,
177187 } ) }
178188 >
179189 Create New Chat
@@ -209,36 +219,44 @@ export default recipe<Input, Output>(
209219 </ aside >
210220
211221 < aside slot = "right" >
212- { ifElse (
213- selectedCharm . charm ,
214- < >
215- < div >
216- < label > Backlinks</ label >
217- < ct-vstack >
218- { selectedCharm ?. charm ?. backlinks ?. map ( (
219- charm : MentionableCharm ,
220- ) => (
221- < ct-button onClick = { handleCharmLinkClicked ( { charm } ) } >
222- { charm [ NAME ] }
223- </ ct-button >
224- ) ) }
225- </ ct-vstack >
226- </ div >
227- < details >
228- < summary > Mentioned Charms</ summary >
229- < ct-vstack >
230- { selectedCharm ?. charm ?. mentioned ?. map ( (
231- charm : MentionableCharm ,
232- ) => (
233- < ct-button onClick = { handleCharmLinkClicked ( { charm } ) } >
234- { charm [ NAME ] }
235- </ ct-button >
236- ) ) }
237- </ ct-vstack >
238- </ details >
239- </ > ,
240- null ,
241- ) }
222+ { derive ( selectedCharm . charm , ( selected ) => {
223+ if ( selected ) {
224+ return (
225+ < >
226+ < div >
227+ < label > Backlinks</ label >
228+ < ct-vstack >
229+ { selected ?. backlinks ?. map ( (
230+ charm : MentionableCharm ,
231+ ) => (
232+ < ct-button
233+ onClick = { handleCharmLinkClicked ( { charm } ) }
234+ >
235+ { charm [ NAME ] }
236+ </ ct-button >
237+ ) ) }
238+ </ ct-vstack >
239+ </ div >
240+ < details >
241+ < summary > Mentioned Charms</ summary >
242+ < ct-vstack >
243+ { selected ?. mentioned ?. map ( (
244+ charm : MentionableCharm ,
245+ ) => (
246+ < ct-button
247+ onClick = { handleCharmLinkClicked ( { charm } ) }
248+ >
249+ { charm [ NAME ] }
250+ </ ct-button >
251+ ) ) }
252+ </ ct-vstack >
253+ </ details >
254+ </ >
255+ ) ;
256+ } else {
257+ return null ;
258+ }
259+ } ) }
242260 </ aside >
243261 </ ct-autolayout >
244262 </ ct-screen >
0 commit comments