Skip to content

Commit

Permalink
Add not found state for community page
Browse files Browse the repository at this point in the history
  • Loading branch information
kgilles committed Dec 23, 2023
1 parent 374b8a8 commit 0c17207
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/app/c/[comSlug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { notFound } from 'next/navigation';

import PostFeed from '@/components/post-feed';
import { H1 } from '@/components/text';
import sublinksClient from '@/utils/client';
import { getCommunityNameFromSlug } from '@/utils/communities';

Expand All @@ -12,18 +14,28 @@ interface CommunityFeedProps {
}

const CommunityFeed = async ({ params: { comSlug } }: CommunityFeedProps) => {
const communityName = getCommunityNameFromSlug(comSlug);
const postsRes = await sublinksClient().getPosts({
community_name: communityName,
type_: 'All',
sort: 'Active'
});
try {
const communityName = getCommunityNameFromSlug(comSlug);
const communityData = await sublinksClient().getCommunity({
name: communityName
});

return (
<div>
<PostFeed data={postsRes.posts} isCommunityFeed />
</div>
);
const communityPostsData = await sublinksClient().getPosts({
community_name: communityName,
type_: 'All',
sort: 'Active'
});
const { title } = communityData.community_view.community;

return (
<div>
<H1 className="ml-8">{title}</H1>
<PostFeed data={communityPostsData.posts} isCommunityFeed />
</div>
);
} catch (e) {
return notFound();
}
};

export default CommunityFeed;

0 comments on commit 0c17207

Please sign in to comment.