import { Fragment } from 'react'; import { AiOutlineFork, AiOutlineStar } from 'react-icons/ai'; import { MdInsertLink } from 'react-icons/md'; import { ga, getLanguageColor, skeleton } from '../../utils'; import { GithubProject } from '../../interfaces/github-project'; const GithubProjectCard = ({ header, githubProjects, loading, limit, username, googleAnalyticsId, }: { header: string; githubProjects: GithubProject[]; loading: boolean; limit: number; username: string; googleAnalyticsId?: string; }) => { if (!loading && githubProjects.length === 0) { return; } const renderSkeleton = () => { const array = []; for (let index = 0; index < limit; index++) { array.push(
{skeleton({ widthCls: 'w-32', heightCls: 'h-8', className: 'mb-1', })}
{skeleton({ widthCls: 'w-full', heightCls: 'h-4', className: 'mb-2', })} {skeleton({ widthCls: 'w-full', heightCls: 'h-4' })}
{skeleton({ widthCls: 'w-12', heightCls: 'h-4' })} {skeleton({ widthCls: 'w-12', heightCls: 'h-4' })}
{skeleton({ widthCls: 'w-12', heightCls: 'h-4' })}
, ); } return array; }; const renderProjects = () => { return githubProjects.map((item, index) => ( { e.preventDefault(); try { if (googleAnalyticsId) { ga.event('Click project', { project: item.name, }); } } catch (error) { console.error(error); } window?.open(item.html_url, '_blank'); }} >
{item.name}

{item.description}

{item.stargazers_count} {item.forks_count}
{item.language}
)); }; return (
{loading ? ( skeleton({ widthCls: 'w-40', heightCls: 'h-8' }) ) : ( {header} )}
{loading ? ( skeleton({ widthCls: 'w-10', heightCls: 'h-5' }) ) : ( See All )}
{loading ? renderSkeleton() : renderProjects()}
); }; export default GithubProjectCard;