changed to function component. Fixed clickable area size.

This commit is contained in:
Kim, Jimin 2021-09-08 13:02:12 +09:00
parent b2449b589c
commit 67d62676e3

View file

@ -1,6 +1,5 @@
import React from "react"
import styled from "styled-components" import styled from "styled-components"
import { Link } from "react-router-dom" import { useHistory } from "react-router-dom"
import theming from "../theming" import theming from "../theming"
@ -15,21 +14,17 @@ import {
import { Post } from "../types/typings" import { Post } from "../types/typings"
const StyledPostCardContainer = styled(Link)` const StyledPostCard = styled.div`
text-decoration: none; box-shadow: 0 4px 10px rgb(0 0 0 / 10%);
text-align: left;
margin-bottom: 2rem;
cursor: pointer;
color: ${(props) => color: ${(props) =>
theming.theme(props.theme.currentTheme, { theming.theme(props.theme.currentTheme, {
light: theming.light.color1, light: theming.light.color1,
dark: theming.dark.color1, dark: theming.dark.color1,
})}; })};
`
const StyledPostCard = styled.div`
box-shadow: 0 4px 10px rgb(0 0 0 / 10%);
text-align: left;
margin-bottom: 2rem;
padding: 0;
&:hover { &:hover {
box-shadow: ${(props) => box-shadow: ${(props) =>
@ -69,64 +64,61 @@ interface PostCardProps {
postData: _PostDateBase postData: _PostDateBase
} }
export default class PostCard extends React.Component<PostCardProps> { export default function PostCard(props: PostCardProps) {
render() { const history = useHistory()
return (
<StyledPostCardContainer
to={process.env.PUBLIC_URL + this.props.postData.url}
>
<StyledPostCard
key={this.props.postData.url}
className="card main-content"
>
<StyledTitle>
{this.props.postData?.title || "No title"}
</StyledTitle>
<StyledMetaContainer> return (
<TagList direction="left"> <StyledPostCard
{this.props.postData.tags ? ( key={props.postData.url}
this.props.postData.tags.map((tag) => { className="card main-content"
return ( onClick={() => {
<Tag history.push({
key={ pathname: process.env.PUBLIC_URL + props.postData.url,
this.props.postData.title + tag })
} }}
text={tag} >
/> <StyledTitle>{props.postData?.title || "No title"}</StyledTitle>
)
})
) : (
<></>
)}
</TagList>
<FontAwesomeIcon icon={faCalendar} />
&nbsp;&nbsp;&nbsp;
{this.props.postData?.date || "Unknown date"}
&nbsp;&nbsp;&nbsp;&nbsp;
<FontAwesomeIcon icon={faHourglass} />
&nbsp;&nbsp;&nbsp;
{this.props.postData?.readTime
? this.props.postData.readTime + " read"
: "unknown length"}
&nbsp;&nbsp;&nbsp;&nbsp;
<FontAwesomeIcon icon={faBook} />
&nbsp;&nbsp;&nbsp;
{this.props.postData?.wordCount
? this.props.postData.wordCount + " words"
: "unknown words"}
</StyledMetaContainer>
<hr /> <StyledMetaContainer>
<TagList direction="left">
{props.postData.tags ? (
props.postData.tags.map((tag) => {
return (
<Tag
key={props.postData.title + tag}
text={tag}
/>
)
})
) : (
<></>
)}
</TagList>
<FontAwesomeIcon icon={faCalendar} />
&nbsp;&nbsp;&nbsp;
{props.postData?.date || "Unknown date"}
&nbsp;&nbsp;&nbsp;&nbsp;
<FontAwesomeIcon icon={faHourglass} />
&nbsp;&nbsp;&nbsp;
{props.postData?.readTime
? props.postData.readTime + " read"
: "unknown length"}
&nbsp;&nbsp;&nbsp;&nbsp;
<FontAwesomeIcon icon={faBook} />
&nbsp;&nbsp;&nbsp;
{props.postData?.wordCount
? props.postData.wordCount + " words"
: "unknown words"}
</StyledMetaContainer>
<StyledPostCardContent <hr />
className="white-link"
dangerouslySetInnerHTML={{ <StyledPostCardContent
__html: this.props.postData.preview, className="white-link"
}} dangerouslySetInnerHTML={{
/> __html: props.postData.preview,
</StyledPostCard> }}
</StyledPostCardContainer> />
) </StyledPostCard>
} )
} }