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.
43 lines
1.6 KiB
43 lines
1.6 KiB
4 years ago
|
import React from "react"
|
||
4 years ago
|
import {chakra, Heading, VStack, Text, HStack,Button, Flex,PropsOf, Tag, useMediaQuery } from "@chakra-ui/react"
|
||
4 years ago
|
import { Story } from "src/types/story"
|
||
4 years ago
|
import moment from 'moment'
|
||
4 years ago
|
import { IDType } from "src/types/id"
|
||
|
import { getStoryUrl } from "utils/story"
|
||
4 years ago
|
|
||
|
type Props = PropsOf<typeof chakra.div> & {
|
||
4 years ago
|
story: Story
|
||
4 years ago
|
showActions: boolean
|
||
|
onEdit?: any
|
||
|
onDelete?: any
|
||
4 years ago
|
showSource?: boolean
|
||
4 years ago
|
}
|
||
|
|
||
|
|
||
4 years ago
|
export const TextStoryCard= (props:Props) =>{
|
||
|
const {story,showActions,onEdit,onDelete,showSource=true ,...rest} = props
|
||
4 years ago
|
|
||
4 years ago
|
const [isSmallScreen] = useMediaQuery("(max-width: 768px)")
|
||
|
const Lay = isSmallScreen ? VStack : Flex
|
||
4 years ago
|
const gap = moment(story.created).fromNow()
|
||
|
|
||
4 years ago
|
return (
|
||
4 years ago
|
//@ts-ignore
|
||
|
<Lay justifyContent="space-between" alignItems={isSmallScreen? "left" : "center"} {...rest}>
|
||
4 years ago
|
<VStack alignItems="left" as="a" href={story.url ?? getStoryUrl(story)} spacing={{base: 4, md: 2}}>
|
||
4 years ago
|
<Heading size="sm" display="flex" alignItems="center">
|
||
4 years ago
|
{showSource && <> {story.url ? <Tag size="sm" mr="2">外部</Tag> : <Tag size="sm" mr="2">原创</Tag>}</>}
|
||
|
{story.title ?story.title : 'No Title'}
|
||
4 years ago
|
</Heading>
|
||
|
<Text fontSize=".9rem">发布于{gap}</Text>
|
||
|
</VStack>
|
||
4 years ago
|
{props.showActions && <HStack pt={{base: 3, md: 0}}>
|
||
4 years ago
|
<Button size="sm" colorScheme="teal" variant="outline" onClick={onEdit}>Edit</Button>
|
||
4 years ago
|
<Button size="sm" onClick={props.onDelete} variant="ghost">Delete</Button>
|
||
4 years ago
|
</HStack>}
|
||
4 years ago
|
</Lay>
|
||
4 years ago
|
)
|
||
|
}
|
||
|
|
||
4 years ago
|
export default TextStoryCard
|