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;