@@ -72,6 +72,7 @@ module Item = {
7272 category : Category .t ,
7373 children : React .element ,
7474 status : Status .t ,
75+ href : string ,
7576 }
7677
7778 let compare = (a , b ) =>
@@ -90,30 +91,20 @@ type itemInfo = {
9091 status : Status .t ,
9192}
9293
93- let getAnchor = path => {
94- switch String .split (path , "#" ) {
95- | [_ , anchor ] => Some (anchor )
96- | _ => None
97- }
98- }
99-
10094module Tag = {
10195 @react.component
102- let make = (~deprecated : bool , ~text : string , ~id : string ) => {
103- let navigate = ReactRouter .useNavigate ()
104- let onClick = evt => {
105- navigate ("#" ++ id )
106- }
107- <span
108- onClick
96+ let make = (~deprecated : bool , ~text : string , ~id : string , ~href ) => {
97+ // Console.log(id)
98+ <ReactRouter .Link .String
99+ to = {"/syntax-lookup/" ++ href }
109100 className = {`
110101 py-1 px-3 rounded text-16
111102 ${deprecated
112103 ? "hover:bg-gray-30 bg-gray-50 text-gray-80 line-through"
113104 : "hover:bg-fire hover:text-white bg-fire-5 text-fire" }` }
114105 >
115106 {React .string (text )}
116- </span >
107+ </ReactRouter . Link . String >
117108 }
118109}
119110
@@ -137,8 +128,7 @@ module DetailBox = {
137128
138129 <div >
139130 <div className = "text-24 border-b border-gray-40 pb-4 mb-4 font-semibold" > summaryEl </div >
140- // TODO: get the actual children
141- <div className = "mt-16" > children </div >
131+ <div className = "mt-16 markdown-body" > children </div >
142132 </div >
143133 }
144134}
@@ -190,21 +180,17 @@ type item = {
190180 category : Category .t ,
191181 children : React .element ,
192182 status : Status .t ,
183+ href : string ,
193184}
194185
195186@react.component
196- let make = (~mdxSources : array <item >) => {
187+ let make = (
188+ ~mdxSources : array <item >,
189+ ~children : option <React .element >= React .null ,
190+ ~activeItem : option <item >= ?,
191+ ) => {
197192 let allItems = mdxSources -> Array .map (mdxSource => {
198- let {id , keywords , category , summary , name , status } = mdxSource
199-
200- // TODO: children?
201- // let children =
202- // <MdxRemote
203- // frontmatter={mdxSource.frontmatter}
204- // compiledSource={mdxSource.compiledSource}
205- // scope={mdxSource.scope}
206- // components={MarkdownComponents.default}
207- // />
193+ let {id , keywords , category , summary , name , status , href } = mdxSource
208194
209195 {
210196 Item .id ,
@@ -213,7 +199,8 @@ let make = (~mdxSources: array<item>) => {
213199 summary ,
214200 name ,
215201 status ,
216- children : <div > {React .string ("Hello!" )} </div >,
202+ children ,
203+ href ,
217204 }
218205 })
219206
@@ -231,7 +218,12 @@ let make = (~mdxSources: array<item>) => {
231218 let fuse : Fuse .t <Item .t > = Fuse .make (allItems , fuseOpts )
232219
233220 let location = ReactRouter .useLocation ()
234- let (state , setState ) = React .useState (_ => ShowAll )
221+ let (state , setState ) = React .useState (_ => {
222+ switch activeItem {
223+ | Some (item ) => ShowDetails ((item :> Item .t ))
224+ | None => ShowAll
225+ }
226+ })
235227
236228 let findItemById = id => allItems -> Array .find (item => "#" ++ item .id === id )
237229
@@ -250,26 +242,6 @@ let make = (~mdxSources: array<item>) => {
250242
251243 let navigate = ReactRouter .useNavigate ()
252244
253- // This effect is responsible for updating the view state when the router anchor changes.
254- // This effect is triggered when:
255- // [A] The page first loads.
256- // [B] The search box is cleared.
257- // [C] The search box value exactly matches an item name.
258- React .useEffect (() => {
259- switch location .hash {
260- | None => setState (_ => ShowAll )
261- | Some (anchor ) =>
262- switch findItemById (anchor ) {
263- | None => setState (_ => ShowAll )
264- | Some (item ) => {
265- setState (_ => ShowDetails (item ))
266- scrollToTop ()
267- }
268- }
269- }
270- None
271- }, [location .hash ])
272-
273245 // onSearchValueChange() is called when:
274246 // [A] The search value changes.
275247 // [B] The search is cleared.
@@ -288,7 +260,7 @@ let make = (~mdxSources: array<item>) => {
288260 let filtered = searchItems (value )
289261 setState (_ => ShowFiltered (value , filtered ))
290262 }
291- | Some (item ) => ReactRouter .navigate ("/syntax-lookup# " ++ item .id )
263+ | Some (item ) => ReactRouter .navigate ("/syntax-lookup/ " ++ item .id )
292264 }
293265 }
294266 }
@@ -298,7 +270,7 @@ let make = (~mdxSources: array<item>) => {
298270 | ShowAll => React .null
299271 | ShowDetails (item ) =>
300272 <div className = "mb-16" >
301- <DetailBox summary = {item .summary }> item . children </DetailBox >
273+ <DetailBox summary = {item .summary }> children </DetailBox >
302274 </div >
303275 }
304276
@@ -347,7 +319,9 @@ let make = (~mdxSources: array<item>) => {
347319 onSearchValueChange (item .name )
348320 }
349321 <span className = "mr-2 mb-2 cursor-pointer" onMouseDown key = item .name >
350- <Tag text = {item .name } deprecated = {item .status == Deprecated } id = item .id />
322+ <Tag
323+ text = {item .name } deprecated = {item .status == Deprecated } id = item .id href = item .href
324+ />
351325 </span >
352326 })
353327 let el =
0 commit comments