@@ -99,8 +99,13 @@ let getAnchor = path => {
9999
100100module Tag = {
101101 @react.component
102- let make = (~deprecated : bool , ~text : string ) => {
102+ let make = (~deprecated : bool , ~text : string , ~id : string ) => {
103+ let navigate = ReactRouter .useNavigate ()
104+ let onClick = evt => {
105+ navigate ("#" ++ id )
106+ }
103107 <span
108+ onClick
104109 className = {`
105110 py-1 px-3 rounded text-16
106111 ${deprecated
@@ -132,6 +137,7 @@ module DetailBox = {
132137
133138 <div >
134139 <div className = "text-24 border-b border-gray-40 pb-4 mb-4 font-semibold" > summaryEl </div >
140+ // TODO: get the actual children
135141 <div className = "mt-16" > children </div >
136142 </div >
137143 }
@@ -144,7 +150,6 @@ type state =
144150
145151let scrollToTop = () => WebAPI .Window .scrollTo (window , ~options = {left : 0.0 , top : 0.0 })
146152
147- type props = {mdxSources : array <MdxRemote .output >}
148153type params = {slug : string }
149154
150155let decode = (json : JSON .t ) => {
@@ -177,21 +182,39 @@ let decode = (json: JSON.t) => {
177182 }
178183}
179184
180- let make = (props : props ) => {
181- let {mdxSources } = props
185+ type item = {
186+ id : string ,
187+ keywords : array <string >,
188+ name : string ,
189+ summary : string ,
190+ category : Category .t ,
191+ children : React .element ,
192+ status : Status .t ,
193+ }
182194
195+ @react.component
196+ let make = (~mdxSources : array <item >) => {
183197 let allItems = mdxSources -> Array .map (mdxSource => {
184- let {id , keywords , category , summary , name , status } = decode (mdxSource .frontmatter )
185-
186- let children =
187- <MdxRemote
188- frontmatter = {mdxSource .frontmatter }
189- compiledSource = {mdxSource .compiledSource }
190- scope = {mdxSource .scope }
191- components = {MarkdownComponents .default }
192- />
193-
194- {Item .id , keywords , category , summary , name , status , children }
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+ // />
208+
209+ {
210+ Item .id ,
211+ keywords ,
212+ category ,
213+ summary ,
214+ name ,
215+ status ,
216+ children : <div > {React .string ("Hello!" )} </div >,
217+ }
195218 })
196219
197220 let fuseOpts = Fuse .Options .t (
@@ -210,9 +233,13 @@ let make = (props: props) => {
210233 let location = ReactRouter .useLocation ()
211234 let (state , setState ) = React .useState (_ => ShowAll )
212235
213- let findItemById = id => allItems -> Array .find (item => item .id === id )
236+ let findItemById = id => allItems -> Array .find (item => "#" ++ item .id === id )
214237
215- let findItemByExactName = name => allItems -> Array .find (item => item .name === name )
238+ let findItemByExactName = name => {
239+ allItems -> Array .find (item => {
240+ item .name === name
241+ })
242+ }
216243
217244 let searchItems = value =>
218245 fuse
@@ -221,13 +248,15 @@ let make = (props: props) => {
221248 m ["item" ]
222249 })
223250
251+ let navigate = ReactRouter .useNavigate ()
252+
224253 // This effect is responsible for updating the view state when the router anchor changes.
225254 // This effect is triggered when:
226255 // [A] The page first loads.
227256 // [B] The search box is cleared.
228257 // [C] The search box value exactly matches an item name.
229258 React .useEffect (() => {
230- switch getAnchor (( location .pathname :> string )) {
259+ switch location .hash {
231260 | None => setState (_ => ShowAll )
232261 | Some (anchor ) =>
233262 switch findItemById (anchor ) {
@@ -239,7 +268,7 @@ let make = (props: props) => {
239268 }
240269 }
241270 None
242- }, [location .pathname ])
271+ }, [location .hash ])
243272
244273 // onSearchValueChange() is called when:
245274 // [A] The search value changes.
@@ -252,7 +281,7 @@ let make = (props: props) => {
252281 // [3] Search does not match an item - immediately update the view state to show filtered items.
253282 let onSearchValueChange = value => {
254283 switch value {
255- | "" => ReactRouter . navigate ("/syntax-lookup" )
284+ | "" => navigate ("/syntax-lookup" )
256285 | value =>
257286 switch findItemByExactName (value ) {
258287 | None => {
@@ -318,7 +347,7 @@ let make = (props: props) => {
318347 onSearchValueChange (item .name )
319348 }
320349 <span className = "mr-2 mb-2 cursor-pointer" onMouseDown key = item .name >
321- <Tag text = {item .name } deprecated = {item .status == Deprecated } />
350+ <Tag text = {item .name } deprecated = {item .status == Deprecated } id = item . id />
322351 </span >
323352 })
324353 let el =
@@ -392,20 +421,3 @@ let make = (props: props) => {
392421 </div >
393422 </>
394423}
395-
396- let getStaticProps : Next .GetStaticProps .t <props , params > = async _ctx => {
397- let dir = Node .Path .resolve ("misc_docs" , "syntax" )
398-
399- let allFiles = Node .Fs .readdirSync (dir )-> Array .map (async file => {
400- let fullPath = Node .Path .join2 (dir , file )
401- let source = fullPath -> Node .Fs .readFileSync
402- await MdxRemote .serialize (
403- source ,
404- {parseFrontmatter : true , mdxOptions : MdxRemote .defaultMdxOptions },
405- )
406- })
407-
408- let mdxSources = await Promise .all (allFiles )
409-
410- {"props" : {mdxSources : mdxSources }}
411- }
0 commit comments