From e7f3b0d7cea82e62ba3002bfa205beec1766fd75 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Fri, 21 Feb 2020 04:10:14 +0300 Subject: [PATCH 1/4] move to ts --- .../{Article.js => Article/index.tsx} | 17 ++++++++++------- src/style/components/Article.scss | 8 +------- 2 files changed, 11 insertions(+), 14 deletions(-) rename src/components/{Article.js => Article/index.tsx} (71%) diff --git a/src/components/Article.js b/src/components/Article/index.tsx similarity index 71% rename from src/components/Article.js rename to src/components/Article/index.tsx index 7e71c0bb..0be499cc 100644 --- a/src/components/Article.js +++ b/src/components/Article/index.tsx @@ -1,6 +1,5 @@ -import React from 'react' -import { dateFormat } from '../lib/date' -import { Share } from './Share' +import { dateFormat } from 'src/lib/date' +import { Share } from '../Share' const Tag = ({ children }) => (
  • @@ -18,10 +17,16 @@ const TagList = ({ tags }) => ( const Head = ({ date, tags = [], children }) => (
    + +

    {children}

    {!date ? null : ( -

    {dateFormat(date)}

    +

    {dateFormat(date)}

    )} {!(tags.length) ? null : ( @@ -30,7 +35,7 @@ const Head = ({ date, tags = [], children }) => (
    ) -const Article = ({ children, date, tags, title, shareable }) => ( +export const Article = ({ children, date, tags, title, shareable }) => (
    ( )}
    ) - -export default Article diff --git a/src/style/components/Article.scss b/src/style/components/Article.scss index 12fa83c1..f172e585 100644 --- a/src/style/components/Article.scss +++ b/src/style/components/Article.scss @@ -15,13 +15,7 @@ margin-bottom: var(--article-head-margin-bottom); } - .date { - text-align: center; - color: #aaa; - - margin-bottom: 1.25em; - } - } + } &-Body { --text-margin: 10px; From 65507c5d800cf402d301fc8a0349a6f1a044435f Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Fri, 21 Feb 2020 04:26:48 +0300 Subject: [PATCH 2/4] article tags refactoring --- pages/article/[slug].tsx | 5 +++-- src/components/Article/index.tsx | 32 +++++++++++++-------------- src/components/TagList/index.tsx | 27 ++++++++++++++++++++++ src/components/TagList/styles.css | 17 ++++++++++++++ src/style/components/ArticleTags.scss | 29 ------------------------ src/style/style.scss | 1 - src/types.ts | 7 ++++++ 7 files changed, 70 insertions(+), 48 deletions(-) create mode 100644 src/components/TagList/index.tsx create mode 100644 src/components/TagList/styles.css delete mode 100644 src/style/components/ArticleTags.scss diff --git a/pages/article/[slug].tsx b/pages/article/[slug].tsx index b713f1c6..81bc1e11 100644 --- a/pages/article/[slug].tsx +++ b/pages/article/[slug].tsx @@ -1,7 +1,7 @@ import Head from 'next/head' import { get } from 'lodash' import { App } from 'src/components/App' -import Article from 'src/components/Article' +import { Article } from 'src/components/Article' import { Html } from 'src/components/Html' import menuModel from 'src/models/menu' import { buildMenu } from 'src/lib/menu' @@ -9,11 +9,12 @@ import { Meta } from 'src/components/Meta' import { meta } from 'src/lib/meta' import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib' import { NextPage } from 'next' +import { IArticle } from 'src/types' type Props = { pageUrl: string meta: any - data: any //(article) + data: IArticle } const Page: NextPage = props => { diff --git a/src/components/Article/index.tsx b/src/components/Article/index.tsx index 0be499cc..92259602 100644 --- a/src/components/Article/index.tsx +++ b/src/components/Article/index.tsx @@ -1,21 +1,21 @@ import { dateFormat } from 'src/lib/date' import { Share } from '../Share' +import { TagList } from '../TagList' +import { ITag } from 'src/types' -const Tag = ({ children }) => ( -
  • - {children} -
  • -) +export type ArticleProps = { + date: string + title: string + tags: ITag[] + shareable: boolean +} -const TagList = ({ tags }) => ( - -) +type HeadProps = { + date: string + tags: ITag[] +} -const Head = ({ date, tags = [], children }) => ( +const Head: React.FC = ({ date, tags = [], children }) => (