@@ -20,30 +20,46 @@ export const LymphomaPostsListView: React.FC<LymphomaPostsListViewProps> = ({
2020 posts,
2121 ...more
2222} ) => {
23+ const postsByOccurrence = posts . reduce < Map < number , typeof posts > > (
24+ ( acc , post ) => {
25+ const group = acc . get ( post . occurrence ) ?? [ ]
26+ group . push ( post )
27+ acc . set ( post . occurrence , group )
28+ return acc
29+ } ,
30+ new Map ( )
31+ )
32+ const occurrences = Array . from ( postsByOccurrence . keys ( ) ) . sort ( ( a , b ) => b - a )
33+
2334 return (
2435 < MainLayout { ...more } >
2536 < S . Title >
2637 Recent posts about
2738 < br />
2839 my Hodgkin's Lymphoma
2940 </ S . Title >
30- < S . PostCardList >
31- { posts . map ( ( post ) => (
32- < S . PostCardListItem key = { post . id } >
33- < S . PostCard to = { post . slug } >
34- < S . PostCardTitle > { post . title } </ S . PostCardTitle >
35- < S . PostCardMeta >
36- < S . PostCardDateDistance title = { formatRFC7231 ( post . date ) } >
37- { daysAgo ( post . date ) }
38- </ S . PostCardDateDistance >
39- < S . PostCardOccurrenceBadge >
40- Occurrence { post . occurrence }
41- </ S . PostCardOccurrenceBadge >
42- </ S . PostCardMeta >
43- </ S . PostCard >
44- </ S . PostCardListItem >
45- ) ) }
46- </ S . PostCardList >
41+ { occurrences . map ( ( occurrence ) => (
42+ < React . Fragment key = { occurrence } >
43+ < S . OccurrenceDivider > Occurrence { occurrence } </ S . OccurrenceDivider >
44+ < S . PostCardList >
45+ { ( postsByOccurrence . get ( occurrence ) ?? [ ] ) . map ( ( post ) => (
46+ < S . PostCardListItem key = { post . id } >
47+ < S . PostCard to = { post . slug } >
48+ < S . PostCardTitle > { post . title } </ S . PostCardTitle >
49+ < S . PostCardMeta >
50+ < S . PostCardDateDistance title = { formatRFC7231 ( post . date ) } >
51+ { daysAgo ( post . date ) }
52+ </ S . PostCardDateDistance >
53+ < S . PostCardOccurrenceBadge >
54+ Occurrence { post . occurrence }
55+ </ S . PostCardOccurrenceBadge >
56+ </ S . PostCardMeta >
57+ </ S . PostCard >
58+ </ S . PostCardListItem >
59+ ) ) }
60+ </ S . PostCardList >
61+ </ React . Fragment >
62+ ) ) }
4763 </ MainLayout >
4864 )
4965}
0 commit comments