mirror of https://github.com/sunface/rust-course
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
2.1 KiB
52 lines
2.1 KiB
4 years ago
|
import React from "react"
|
||
|
import { Box, chakra, Flex, Heading, HStack, Image, Text, useMediaQuery, VStack } from "@chakra-ui/react"
|
||
|
import { Post } from "src/types/posts"
|
||
|
import PostAuthor from "./post-author"
|
||
|
import Link from "next/link"
|
||
4 years ago
|
import Like from "./like"
|
||
|
import { FaHeart, FaRegHeart } from "react-icons/fa"
|
||
|
import Bookmark from "./bookmark"
|
||
|
import { getSvgIcon } from "components/svg-icon"
|
||
|
import Count from "components/count"
|
||
4 years ago
|
|
||
|
interface Props {
|
||
|
post: Post
|
||
|
}
|
||
|
|
||
|
|
||
|
export const PostCard = (props: Props) => {
|
||
|
const { post } = props
|
||
|
const [isLargeScreen] = useMediaQuery("(min-width: 768px)")
|
||
|
const Layout = isLargeScreen ? HStack : VStack
|
||
|
return (
|
||
4 years ago
|
<VStack alignItems="left" spacing="4" p="2">
|
||
4 years ago
|
<PostAuthor post={post} showFooter={false} size="md" />
|
||
|
<Link href={`/${post.creator.username}/${post.id}`}>
|
||
|
<Layout alignItems={isLargeScreen ? "top" : "left"} cursor="pointer" pl="2" pt="1">
|
||
|
<VStack alignItems="left" spacing="3" width={isLargeScreen ? "calc(100% - 18rem)" : '100%'}>
|
||
|
<Heading size="md">{post.title}</Heading>
|
||
4 years ago
|
<Text layerStyle="textSecondary" maxW="400px">{post.brief}</Text>
|
||
4 years ago
|
</VStack>
|
||
|
{post.cover && <Image src={post.cover} width="18rem" height="120px" pt={isLargeScreen ? 0 : 2} borderRadius="4px" />}
|
||
|
</Layout>
|
||
|
</Link>
|
||
|
|
||
|
<HStack pl="2" spacing="5">
|
||
4 years ago
|
<Like storyID={post.id} liked={post.liked} count={post.likes} fontSize="18px"/>
|
||
4 years ago
|
<Link href={`/${post.creator.username}/${post.id}#comments`}>
|
||
4 years ago
|
<HStack opacity="0.9" cursor="pointer">
|
||
|
{getSvgIcon("comments", "1.3rem")}
|
||
|
<Text ml="2"><Count count={post.comments}/></Text>
|
||
|
</HStack>
|
||
4 years ago
|
</Link>
|
||
|
|
||
|
|
||
|
|
||
4 years ago
|
<Box style={{ marginLeft: '4px' }}><Bookmark height="1.05rem" storyID={post.id} bookmarked={post.bookmarked} /></Box>
|
||
4 years ago
|
</HStack>
|
||
|
</VStack>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
export default PostCard
|