Skip to content

Commit

Permalink
hotfix(frontend): account for slugs being potentially undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-h1 committed Jan 14, 2024
1 parent d6af5b8 commit cec591f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
52 changes: 27 additions & 25 deletions src/app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,32 +64,34 @@ const PostPage = async ({ params }: Props) => {
),
},
{
title: 'Tags',
description: (
// eslint-disable-next-line react/jsx-no-useless-fragment
<>
{post.tags.length > 0
? post.tags.slice(0, 3).map(tag => (
<Link
href={`/blog/tags/${tag.slug.current}`}
key={tag.slug.current}
>
<Text
fontSize="sm"
color="foregroundNeutral"
key={`${tag.title}-${tag.slug.current}`}
data-testid="post-tags"
style={{
marginTop: '0.25rem',
}}
...(post.tags && {
title: 'Tags',
description: (
// eslint-disable-next-line react/jsx-no-useless-fragment
<>
{post.tags.length > 0
? post.tags.slice(0, 3).map(tag => (
<Link
href={`/blog/tags/${tag.slug.current}`}
key={tag.slug.current}
>
#{tag.title}
</Text>
</Link>
))
: null}
</>
),
<Text
fontSize="sm"
color="foregroundNeutral"
key={`${tag.title}-${tag.slug.current}`}
data-testid="post-tags"
style={{
marginTop: '0.25rem',
}}
>
#{tag.title}
</Text>
</Link>
))
: null}
</>
),
}),
},
]}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/app/blog/tags/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const TagPage = async ({ params }: Props) => {
const posts = await postService.getAllPosts();

const matchingPosts = posts.filter(post => {
return post.tags.some(tag => tag.slug.current === slug);
return post.tags && post.tags.some(tag => tag.slug.current === slug);
});

return (
Expand Down
3 changes: 2 additions & 1 deletion src/components/PostCard/PostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ const PostCard = ({ post }: Props) => {
gap="sm"
maxWidth="text"
>
{post.tags.length > 0 &&
{post.tags &&
post.tags.length > 0 &&
post.tags.slice(0, 5).map(tag => (
<Link
href={`/blog/tags/${tag.slug.current}`}
Expand Down

0 comments on commit cec591f

Please sign in to comment.