-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from websitesieutoc/create-post-list
Create page post list
- Loading branch information
Showing
7 changed files
with
115 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
import { Box, GeneralLayout, Heading } from '@/components'; | ||
import { prisma } from '@/utils/prisma'; | ||
import { | ||
Box, | ||
GeneralLayout, | ||
Heading, | ||
SimpleGrid, | ||
Spinner, | ||
Wrap, | ||
} from '@/components'; | ||
import { PostCard } from '@/components/Post'; | ||
|
||
export default function BlogsPage() { | ||
export default async function BlogsPage() { | ||
const data = await prisma?.post.findMany({ | ||
orderBy: { createdAt: 'desc' }, | ||
take: 25, | ||
}); | ||
if (!data) return <Spinner size="sm" />; | ||
return ( | ||
<GeneralLayout> | ||
<Heading>The latest articles</Heading> | ||
<Box>if user login then show button create post</Box> | ||
<Box paddingY={5} /> | ||
<SimpleGrid columns={[2, null, 3]} spacing="10px"> | ||
{data?.map((post, index) => <PostCard key={index} post={post} />)} | ||
</SimpleGrid> | ||
</GeneralLayout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { format } from 'date-fns'; | ||
|
||
import type { FC, Post } from '@/types'; | ||
import { | ||
Flex, | ||
Box, | ||
Card, | ||
Spacer, | ||
Avatar, | ||
Button, | ||
Heading, | ||
NextLink, | ||
CardBody, | ||
CardFooter, | ||
AvatarGroup, | ||
} from '@/components'; | ||
|
||
type PropTypes = { | ||
post: Post; | ||
}; | ||
export const PostCard: FC<PropTypes> = ({ post }) => { | ||
return ( | ||
<Box> | ||
<Card height={400}> | ||
<CardBody padding={3}> | ||
<Flex> | ||
<Box fontSize="sm" color="gray.400"> | ||
{format(post.createdAt, 'PPP')} | ||
</Box> | ||
<Spacer /> | ||
<Box> | ||
<AvatarGroup size="xs" max={2}> | ||
<Avatar | ||
name="Ryan Florence" | ||
src="https://bit.ly/ryan-florence" | ||
/> | ||
<Avatar | ||
name="Segun Adebayo" | ||
src="https://bit.ly/sage-adebayo" | ||
/> | ||
<Avatar name="Kent Dodds" src="https://bit.ly/kent-c-dodds" /> | ||
<Avatar | ||
name="Prosper Otemuyiwa" | ||
src="https://bit.ly/prosper-baba" | ||
/> | ||
<Avatar | ||
name="Christian Nwamba" | ||
src="https://bit.ly/code-beast" | ||
/> | ||
</AvatarGroup> | ||
</Box> | ||
</Flex> | ||
<Box paddingY={3}> | ||
<Heading size="md">{post.title}</Heading> | ||
</Box> | ||
<Box | ||
__css={{ | ||
overflow: 'hidden', | ||
textOverflow: 'ellipsis', | ||
display: '-webkit-box', | ||
WebkitLineClamp: 5, | ||
WebkitBoxOrient: 'vertical', | ||
}} | ||
as="div" | ||
maxHeight={300} | ||
dangerouslySetInnerHTML={{ __html: post?.content ?? '' }} | ||
/> | ||
</CardBody> | ||
<CardFooter padding={2}> | ||
<NextLink href={`/blog/${post.id}`} w="100%"> | ||
<Button width="100%" size="sm"> | ||
Read More | ||
</Button> | ||
</NextLink> | ||
</CardFooter> | ||
</Card> | ||
</Box> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { PostList } from './PostList'; | ||
export { PostCard } from './PostCard'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.