From 50a3df40bc8d41271c4cd8d6873a6d4e1dd87b42 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 20 Jan 2022 19:32:36 +0100 Subject: chore: add a project summary component --- src/components/ProjectSummary/ProjectSummary.tsx | 122 +++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 src/components/ProjectSummary/ProjectSummary.tsx (limited to 'src/components/ProjectSummary/ProjectSummary.tsx') diff --git a/src/components/ProjectSummary/ProjectSummary.tsx b/src/components/ProjectSummary/ProjectSummary.tsx new file mode 100644 index 0000000..0d00f06 --- /dev/null +++ b/src/components/ProjectSummary/ProjectSummary.tsx @@ -0,0 +1,122 @@ +import GithubIcon from '@assets/images/social-media/github.svg'; +import GitlabIcon from '@assets/images/social-media/gitlab.svg'; +import { t } from '@lingui/macro'; +import { getRepoData } from '@services/repos/github'; +import { ProjectMeta } from '@ts/types/app'; +import { RepoData } from '@ts/types/github'; +import { slugify } from '@utils/helpers/slugify'; +import Image from 'next/image'; +import { useRouter } from 'next/router'; +import { useEffect, useState } from 'react'; +import styles from './ProjectSummary.module.scss'; + +const ProjectSummary = ({ + slug, + title, + cover, + meta, +}: { + slug: string; + title: string; + cover: string; + meta: ProjectMeta; +}) => { + const { license, repos, technologies } = meta; + const [data, setData] = useState(); + const { locale } = useRouter(); + const githubUser = process.env.NEXT_PUBLIC_GITHUB_USER; + + useEffect(() => { + getRepoData(slug) + .then((repoData) => setData(repoData)) + .catch((e) => console.error(e)); + }, [slug]); + + const getFormattedDate = (date: string) => { + const dateOptions: Intl.DateTimeFormatOptions = { + day: 'numeric', + month: 'long', + year: 'numeric', + }; + + return new Date(date).toLocaleDateString(locale, dateOptions); + }; + + return ( +
+
+ {t`${title} +
+
+ {data && ( +
+
{t`Created on`}
+
{t`${getFormattedDate(data.created_at)}`}
+
+ )} + {data && ( +
+
{t`Last updated on`}
+
{t`${getFormattedDate(data.updated_at)}`}
+
+ )} +
+
{t`License`}
+
{license}
+
+ {technologies && ( +
+
{t`Technologies`}
+ {technologies.map((techno) => ( +
+ {techno} +
+ ))} +
+ )} + {repos && ( +
+
{t`Repositories`}
+ {repos.github && ( +
+ + + Github + +
+ )} + {repos.gitlab && ( +
+ + + Gitlab + +
+ )} +
+ )} + {data && ( +
+
{t`Popularity`}
+
+ ⭐  + + {t`${data.stargazers_count} stars on Github`} + +
+
+ )} +
+
+ ); +}; + +export default ProjectSummary; -- cgit v1.2.3