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

4 years ago
import React from "react"
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
const [isSmallScreen] = useMediaQuery("(max-width: 768px)")
const Lay = isSmallScreen ? VStack : Flex
4 years ago
const gap = moment(story.created).fromNow()
4 years ago
return (
//@ts-ignore
<Lay justifyContent="space-between" alignItems={isSmallScreen? "left" : "center"} {...rest}>
4 years ago
<VStack alignItems="left" as="a" href={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>
{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>}
</Lay>
4 years ago
)
}
4 years ago
export default TextStoryCard