Skip to content

Commit 952ae42

Browse files
committed
feat: add occurrence handling and styling to lymphoma posts
1 parent b714f4e commit 952ae42

5 files changed

Lines changed: 80 additions & 17 deletions

File tree

‎src/layouts/PostLayout.styles.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ export const PostCategory = styled.div`
2727

2828
export const PostTitle = styled(PageTitle)``
2929

30+
export const PostOccurrence = styled.div`
31+
display: flex;
32+
justify-content: center;
33+
margin: 0.5rem 0;
34+
`
35+
36+
export const PostOccurrenceBadge = styled.span`
37+
font-size: ${$theme.fontSize.copy2}rem;
38+
font-weight: ${$theme.fontWeight.semiBold};
39+
color: ${$theme.color.primary};
40+
background-color: ${$theme.color.secondary}33;
41+
border: 1px solid ${$theme.color.secondary};
42+
border-radius: 999px;
43+
padding: 0.1rem 0.6rem;
44+
line-height: 1.4;
45+
`
46+
3047
export const PostDate = styled.small`
3148
display: block;
3249
text-align: center;

‎src/layouts/PostLayout.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type PostLayoutProps = {
88
title: string
99
date: Date
1010
category: string
11+
occurrence?: number
1112
contents: any
1213
previousSlug: string
1314
nextSlug: string
@@ -17,6 +18,7 @@ export const PostLayout: React.FC<PostLayoutProps> = ({
1718
title,
1819
date,
1920
category,
21+
occurrence,
2022
contents,
2123
previousSlug,
2224
nextSlug,
@@ -27,6 +29,13 @@ export const PostLayout: React.FC<PostLayoutProps> = ({
2729
<S.Container>
2830
<S.PostCategory>{category}</S.PostCategory>
2931
<S.PostTitle>{title}</S.PostTitle>
32+
{occurrence != null && (
33+
<S.PostOccurrence>
34+
<S.PostOccurrenceBadge>
35+
Occurrence {occurrence}
36+
</S.PostOccurrenceBadge>
37+
</S.PostOccurrence>
38+
)}
3039
<S.PostDate>{formatRFC7231(date)}</S.PostDate>
3140
<S.PostContents dangerouslySetInnerHTML={{ __html: contents }} />
3241
<S.PostFooter>

‎src/pages/{MarkdownRemark.frontmatter__slug}.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type TemplateProps = {
1414
date: string
1515
slug: string
1616
title: string
17+
occurrence: number | null
1718
}
1819
}
1920
allMarkdownRemark: {
@@ -65,6 +66,7 @@ const Template: React.FC<TemplateProps> = ({ data, ...more }) => {
6566
title={frontmatter.title}
6667
date={parseISO(frontmatter.date)}
6768
category={getBlogNameById(categoryId)}
69+
occurrence={frontmatter.occurrence ?? undefined}
6870
contents={html}
6971
previousSlug={previousSlug}
7072
nextSlug={nextSlug}
@@ -82,6 +84,7 @@ export const pageQuery = graphql`
8284
date
8385
slug
8486
title
87+
occurrence
8588
}
8689
}
8790
allMarkdownRemark(sort: { frontmatter: { date: ASC } }) {

‎src/views/LymphomaPostsListView.styles.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,25 @@ export const PostCardDateDistance = styled.span`
5151
font-size: ${$theme.fontSize.copy2}rem;
5252
`
5353

54+
export const OccurrenceDivider = styled.div`
55+
display: flex;
56+
align-items: center;
57+
gap: 0.75rem;
58+
margin: 2rem 0 0.5rem;
59+
font-size: ${$theme.fontSize.copy2}rem;
60+
font-weight: ${$theme.fontWeight.semiBold};
61+
color: ${$theme.color.copyLight};
62+
63+
&::before,
64+
&::after {
65+
content: '';
66+
flex: 1;
67+
border-top: 1px solid ${$theme.color.secondary};
68+
}
69+
`
70+
5471
export const PostCardOccurrenceBadge = styled.span`
72+
margin-left: auto;
5573
font-size: ${$theme.fontSize.copy2}rem;
5674
font-weight: ${$theme.fontWeight.semiBold};
5775
color: ${$theme.color.primary};

‎src/views/LymphomaPostsListView.tsx‎

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)