From 05b1b6334745921c545ad5ec36ef1d755a3fc0e4 Mon Sep 17 00:00:00 2001 From: developomp Date: Sun, 1 Aug 2021 10:39:25 +0900 Subject: [PATCH] moved post card to separate component --- source/src/components/PostCard.tsx | 103 +++++++++++++++++++++++++++++ source/src/pages/PostList.tsx | 75 +-------------------- 2 files changed, 106 insertions(+), 72 deletions(-) create mode 100644 source/src/components/PostCard.tsx diff --git a/source/src/components/PostCard.tsx b/source/src/components/PostCard.tsx new file mode 100644 index 0000000..f5c3331 --- /dev/null +++ b/source/src/components/PostCard.tsx @@ -0,0 +1,103 @@ +import React from "react" +import marked from "marked" +import styled from "styled-components" +import { Link } from "react-router-dom" + +import theming from "../theming" +import Tag from "../components/Tag" + +const StyledTitle = styled.h1` + font-size: 2rem; + font-style: bold; + margin-bottom: 1rem; +` + +const StyledLink = styled(Link)` + text-decoration: none; + + color: ${(props) => + theming.theme(props.theme.currentTheme, { + light: "black", + dark: "white", + })}; + + &:hover { + text-decoration: underline; + } +` + +const StyledPostCard = styled.div` + box-shadow: 0 4px 10px rgb(0 0 0 / 10%); + text-align: left; + margin-bottom: 20px; + padding: 1rem 2rem 2rem 2rem; +` + +const StyledPostCardContent = styled.div` + color: ${(props) => + theming.theme(props.theme.currentTheme, { + light: "grey", + dark: "darkgrey", + })}; +` + +interface PostCardProps { + postData: { + url: string + title: string | undefined + preview: string + tags: string[] + date: string | undefined + } +} + +export default class PostCard extends React.Component { + render() { + return ( + + + + {this.props.postData?.title + ? this.props.postData.title + : "No title"} + + + + + {this.props.postData.tags.map((tag) => { + return ( + + ) + })} +
+ +
+ Published on{" "} + {this.props.postData?.date + ? this.props.postData.date + : "Unknown date"} +
+ +
+ + + + Read more + + +
+ ) + } +} diff --git a/source/src/pages/PostList.tsx b/source/src/pages/PostList.tsx index 2441205..584c404 100644 --- a/source/src/pages/PostList.tsx +++ b/source/src/pages/PostList.tsx @@ -3,14 +3,13 @@ */ import React from "react" -import { Link } from "react-router-dom" import styled from "styled-components" -import marked from "marked" import { Helmet } from "react-helmet-async" import theming from "../theming" import posts from "../data/map.json" -import Tag from "../components/Tag" + +import PostCard from "../components/PostCard" const StyledPostList = styled.div` padding-top: 2rem; @@ -29,41 +28,6 @@ const StyledH1 = styled.h1` margin: 0; ` -const StyledTitle = styled.h1` - font-size: 2rem; - font-style: bold; - margin-bottom: 1rem; -` - -const StyledLink = styled(Link)` - text-decoration: none; - - color: ${(props) => - theming.theme(props.theme.currentTheme, { - light: "black", - dark: "white", - })}; - - &:hover { - text-decoration: underline; - } -` - -const StyledPostCard = styled.div` - box-shadow: 0 4px 10px rgb(0 0 0 / 10%); - text-align: left; - margin-bottom: 20px; - padding: 1rem 2rem 2rem 2rem; -` - -const StyledPostCardContent = styled.div` - color: ${(props) => - theming.theme(props.theme.currentTheme, { - light: "grey", - dark: "darkgrey", - })}; -` - interface PostListProps { title: string howMany?: number @@ -115,40 +79,7 @@ export default class PostList extends React.Component< for (const postIndex in recentPosts) { const [url, post] = recentPosts[postIndex] - PostCards.push( - - - - {post?.title ? post.title : "No title"} - - - - - {post.tags.map((tag) => { - return ( - - ) - })} -
- -
- Published on {post?.date ? post.date : "Unknown date"} -
- -
- - - - Read more - - -
- ) + PostCards.push() } this.setState({