@@ -39,44 +39,34 @@ module Badge = {
39
39
</div >
40
40
}
41
41
}
42
- module CategorySelector = {
43
- type selection =
44
- | All
45
- | Archived
46
42
47
- let renderTab = (~text : string , ~isActive : bool , ~onClick ) => {
48
- let active = "bg-gray-20 text-gray-80 rounded py-1"
49
- <div
50
- key = text
51
- onClick
52
- className = {(
53
- isActive ? active : "hover:cursor-pointer bg-white hover:text-gray-80"
54
- ) ++ " px-4 inline-block" }>
55
- {React .string (text )}
56
- </div >
57
- }
43
+ type category =
44
+ | /** Actually only unarchived */ All
45
+ | Archived
58
46
47
+ module CategorySelector = {
59
48
@react.component
60
- let make = (~selected : selection , ~ onSelected : selection => unit ) => {
49
+ let make = (~selected : category ) => {
61
50
let tabs = [All , Archived ]
62
51
63
52
<div className = "text-16 w-full flex items-center justify-between text-gray-60" >
64
- {Belt .Array .map (tabs , tab => {
65
- let onClick = evt => {
66
- evt -> ReactEvent .Mouse .preventDefault
67
- onSelected (tab )
68
- }
69
-
53
+ {tabs
54
+ -> Belt .Array .map (tab => {
70
55
// Deep comparison here!
71
56
let isActive = selected == tab
72
-
73
- let text = switch tab {
74
- | All => "All "
75
- | Archived => "Archived "
57
+ let text = ( tab :> string )
58
+ let href = switch tab {
59
+ | All => "/blog "
60
+ | Archived => "/blog/archived "
76
61
}
77
-
78
- renderTab (~isActive , ~text , ~onClick )
79
- })-> React .array }
62
+ let className =
63
+ switch isActive {
64
+ | true => "bg-gray-20 text-gray-80 rounded py-1"
65
+ | false => "hover:cursor-pointer bg-white hover:text-gray-80"
66
+ } ++ " px-4 inline-block"
67
+ <Link key = text href className > {React .string (text )} </Link >
68
+ })
69
+ -> React .array }
80
70
</div >
81
71
}
82
72
}
@@ -209,15 +199,10 @@ module FeatureCard = {
209
199
210
200
type params = {slug : string }
211
201
212
- type props = {
213
- posts : array <BlogApi .post >,
214
- archived : array <BlogApi .post >,
215
- }
202
+ type props = {posts : array <BlogApi .post >, category : category }
216
203
217
204
let default = (props : props ): React .element => {
218
- let {posts , archived } = props
219
-
220
- let (currentSelection , setSelection ) = React .useState (() => CategorySelector .All )
205
+ let {posts , category } = props
221
206
222
207
let content = if Belt .Array .length (posts ) === 0 {
223
208
/* <div> {React.string("Currently no posts available")} </div>; */
@@ -226,16 +211,11 @@ let default = (props: props): React.element => {
226
211
<Markdown .Warn > {React .string ("This blog is currently in the works." )} </Markdown .Warn >
227
212
</div >
228
213
} else {
229
- let filtered = switch currentSelection {
230
- | All => posts
231
- | Archived => archived
232
- }
233
-
234
- let result = switch Belt .Array .length (filtered ) {
214
+ let result = switch Belt .Array .length (posts ) {
235
215
| 0 => <div > {React .string ("No posts for this category available..." )} </div >
236
216
| _ =>
237
- let first = Belt .Array .getExn (filtered , 0 )
238
- let rest = Js .Array2 .sliceFrom (filtered , 1 )
217
+ let first = Belt .Array .getExn (posts , 0 )
218
+ let rest = Js .Array2 .sliceFrom (posts , 1 )
239
219
240
220
let featureBox =
241
221
<div className = "w-full mb-24 lg:px-8 xl:px-0" >
@@ -280,9 +260,7 @@ let default = (props: props): React.element => {
280
260
<>
281
261
<div className = "hidden sm:flex justify-center " >
282
262
<div className = "my-16 w-full" style = {ReactDOMStyle .make (~maxWidth = "12rem" , ())}>
283
- <CategorySelector
284
- onSelected = {selection => setSelection (_ => selection )} selected = currentSelection
285
- />
263
+ <CategorySelector selected = category />
286
264
</div >
287
265
</div >
288
266
result
@@ -316,12 +294,19 @@ let default = (props: props): React.element => {
316
294
</>
317
295
}
318
296
319
- let getStaticProps : Next .GetStaticProps .t <props , params > = async _ctx => {
320
- let (archived , nonArchived ) = BlogApi .getAllPosts ()-> Belt .Array .partition (data => data .archived )
297
+ let getStaticProps_All : Next .GetStaticProps .t <props , params > = async _ctx => {
298
+ let props = {
299
+ posts : BlogApi .getLivePosts (),
300
+ category : All ,
301
+ }
302
+
303
+ {"props" : props }
304
+ }
321
305
306
+ let getStaticProps_Archived : Next .GetStaticProps .t <props , params > = async _ctx => {
322
307
let props = {
323
- posts : nonArchived ,
324
- archived ,
308
+ posts : BlogApi . getArchivedPosts () ,
309
+ category : Archived ,
325
310
}
326
311
327
312
{"props" : props }
0 commit comments