@@ -42,15 +42,43 @@ module Category = {
42
42
}
43
43
}
44
44
45
- // The data representing a syntax construct
46
- // handled in the widget
47
- type item = {
48
- id : string ,
49
- keywords : array <string >,
50
- name : string ,
51
- summary : string ,
52
- category : Category .t ,
53
- children : React .element ,
45
+ module Status = {
46
+ type t =
47
+ | Active
48
+ | Deprecated
49
+
50
+ let fromString = (s : string ): t =>
51
+ switch s {
52
+ | "deprecated" => Deprecated
53
+ | "active" | _ => Active
54
+ }
55
+
56
+ let compare = (a , b ) =>
57
+ switch (a , b ) {
58
+ | (Deprecated , Deprecated ) | (Active , Active ) => 0
59
+ | (Active , Deprecated ) => - 1
60
+ | (Deprecated , Active ) => 1
61
+ }
62
+ }
63
+
64
+ module Item = {
65
+ // The data representing a syntax construct
66
+ // handled in the widget
67
+ type t = {
68
+ id : string ,
69
+ keywords : array <string >,
70
+ name : string ,
71
+ summary : string ,
72
+ category : Category .t ,
73
+ children : React .element ,
74
+ status : Status .t ,
75
+ }
76
+
77
+ let compare = (a , b ) =>
78
+ switch Status .compare (a .status , b .status ) {
79
+ | 0 => String .compare (a .name , b .name )
80
+ | x => x
81
+ }
54
82
}
55
83
56
84
type itemInfo = {
@@ -59,6 +87,7 @@ type itemInfo = {
59
87
name : string ,
60
88
summary : string ,
61
89
category : Category .t ,
90
+ status : Status .t ,
62
91
}
63
92
64
93
let getAnchor = path => {
@@ -70,8 +99,13 @@ let getAnchor = path => {
70
99
71
100
module Tag = {
72
101
@react.component
73
- let make = (~text : string ) => {
74
- <span className = "hover:bg-fire hover:text-white bg-fire-5 py-1 px-3 rounded text-fire text-16" >
102
+ let make = (~deprecated : bool , ~text : string ) => {
103
+ <span
104
+ className = {`
105
+ py-1 px-3 rounded text-16
106
+ ${deprecated
107
+ ? "hover:bg-gray-30 bg-gray-50 text-gray-80 line-through"
108
+ : "hover:bg-fire hover:text-white bg-fire-5 text-fire" }` }>
75
109
{React .string (text )}
76
110
</span >
77
111
}
@@ -104,8 +138,8 @@ module DetailBox = {
104
138
105
139
type state =
106
140
| ShowAll
107
- | ShowFiltered (string , array <item >) // (search, filteredItems)
108
- | ShowDetails (item )
141
+ | ShowFiltered (string , array <Item . t >) // (search, filteredItems)
142
+ | ShowDetails (Item . t )
109
143
110
144
@val @scope ("window" )
111
145
external scrollTo : (int , int ) => unit = "scrollTo"
@@ -122,21 +156,26 @@ let decode = (json: Js.Json.t) => {
122
156
let name = json -> (field ("name" , string , _ ))
123
157
let summary = json -> (field ("summary" , string , _ ))
124
158
let category = json -> field ("category" , string , _ )-> Category .fromString
159
+ let status =
160
+ json
161
+ -> optional (field ("status" , string , _ ), _ )
162
+ -> Belt .Option .mapWithDefault (Status .Active , Status .fromString )
125
163
126
164
{
127
165
id ,
128
166
keywords ,
129
167
name ,
130
168
summary ,
131
169
category ,
170
+ status ,
132
171
}
133
172
}
134
173
135
174
let default = (props : props ) => {
136
175
let {mdxSources } = props
137
176
138
177
let allItems = mdxSources -> Js .Array2 .map (mdxSource => {
139
- let {id , keywords , category , summary , name } = decode (mdxSource .frontmatter )
178
+ let {id , keywords , category , summary , name , status } = decode (mdxSource .frontmatter )
140
179
141
180
let children =
142
181
<MdxRemote
@@ -146,7 +185,7 @@ let default = (props: props) => {
146
185
components = {MarkdownComponents .default }
147
186
/>
148
187
149
- {id , keywords , category , summary , name , children }
188
+ {Item . id , keywords , category , summary , name , status , children }
150
189
})
151
190
152
191
let fuseOpts = Fuse .Options .t (
@@ -160,7 +199,7 @@ let default = (props: props) => {
160
199
(),
161
200
)
162
201
163
- let fuse : Fuse .t <item > = Fuse .make (allItems , fuseOpts )
202
+ let fuse : Fuse .t <Item . t > = Fuse .make (allItems , fuseOpts )
164
203
165
204
let router = Next .Router .useRouter ()
166
205
let (state , setState ) = React .useState (_ => ShowAll )
@@ -267,14 +306,14 @@ let default = (props: props) => {
267
306
} else {
268
307
let children =
269
308
items
270
- -> Belt .SortArray .stableSortBy (( v1 , v2 ) => String .compare ( v1 . name , v2 . name ) )
309
+ -> Belt .SortArray .stableSortBy (Item .compare )
271
310
-> Belt .Array .map (item => {
272
311
let onMouseDown = evt => {
273
312
ReactEvent .Mouse .preventDefault (evt )
274
313
onSearchValueChange (item .name )
275
314
}
276
315
<span className = "mr-2 mb-2 cursor-pointer" onMouseDown key = item .name >
277
- <Tag text = {item .name } />
316
+ <Tag text = {item .name } deprecated = { item . status == Deprecated } />
278
317
</span >
279
318
})
280
319
let el =
0 commit comments