import { MdLocationOn } from 'react-icons/md'; import { AiFillGithub, AiFillInstagram, AiFillMediumSquare, } from 'react-icons/ai'; import { SiTwitter } from 'react-icons/si'; import { CgDribbble } from 'react-icons/cg'; import { RiPhoneFill, RiMailFill } from 'react-icons/ri'; import { Fragment } from 'react'; import { FaBehanceSquare, FaBuilding, FaDev, FaFacebook, FaGlobe, FaSkype, FaMastodon, FaStackOverflow, FaTelegram, FaLinkedin, FaYoutube, } from 'react-icons/fa'; import { skeleton } from '../../utils'; import { Profile } from '../../interfaces/profile'; import { SanitizedGithub, SanitizedSocial, } from '../../interfaces/sanitized-config'; type Props = { profile: Profile | null; loading: boolean; social: SanitizedSocial; github: SanitizedGithub; }; const isCompanyMention = (company: string): boolean => { return company.startsWith('@') && !company.includes(' '); }; const companyLink = (company: string): string => { return `https://github.com/${company.substring(1)}`; }; const getFormattedMastodonValue = ( mastodonValue: string, isLink: boolean, ): string => { const [username, server] = mastodonValue.split('@'); if (isLink) { return `https://${server}/@${username}`; } else { return `${username}@${server}`; } }; const ListItem: React.FC<{ icon: React.ReactNode; title: React.ReactNode; value: React.ReactNode; link?: string; skeleton?: boolean; }> = ({ icon, title, value, link, skeleton = false }) => { return (
{icon} {title}
{value}
); }; /** * Renders the details card component. * * @param {Object} profile - The profile object. * @param {boolean} loading - Indicates whether the data is loading. * @param {Object} social - The social object. * @param {Object} github - The GitHub object. * @return {JSX.Element} The details card component. */ const DetailsCard = ({ profile, loading, social, github }: Props) => { const renderSkeleton = () => { const array = []; for (let index = 0; index < 4; index++) { array.push( , ); } return array; }; return (
{loading || !profile ? ( renderSkeleton() ) : ( {profile.location && ( } title="Based in:" value={profile.location} /> )} {profile.company && ( } title="Company:" value={profile.company} link={ isCompanyMention(profile.company.trim()) ? companyLink(profile.company.trim()) : undefined } /> )} } title="GitHub:" value={github.username} link={`https://github.com/${github.username}`} /> {social?.twitter && ( } title="Twitter:" value={social.twitter} link={`https://twitter.com/${social.twitter}`} /> )} {social?.mastodon && ( } title="Mastodon:" value={getFormattedMastodonValue(social.mastodon, false)} link={getFormattedMastodonValue(social.mastodon, true)} /> )} {social?.linkedin && ( } title="LinkedIn:" value={social.linkedin} link={`https://www.linkedin.com/in/${social.linkedin}`} /> )} {social?.dribbble && ( } title="Dribbble:" value={social.dribbble} link={`https://dribbble.com/${social.dribbble}`} /> )} {social?.behance && ( } title="Behance:" value={social.behance} link={`https://www.behance.net/${social.behance}`} /> )} {social?.facebook && ( } title="Facebook:" value={social.facebook} link={`https://www.facebook.com/${social.facebook}`} /> )} {social?.instagram && ( } title="Instagram:" value={social.instagram} link={`https://www.instagram.com/${social.instagram}`} /> )} {social?.youtube && ( } title="YouTube:" value={`@${social.youtube}`} link={`https://www.youtube.com/@${social.youtube}`} /> )} {social?.medium && ( } title="Medium:" value={social.medium} link={`https://medium.com/@${social.medium}`} /> )} {social?.dev && ( } title="Dev:" value={social.dev} link={`https://dev.to/${social.dev}`} /> )} {social?.stackoverflow && ( } title="Stack Overflow:" value={social.stackoverflow.split('/').slice(-1)} link={`https://stackoverflow.com/users/${social.stackoverflow}`} /> )} {social?.website && ( } title="Website:" value={social.website .replace('https://', '') .replace('http://', '')} link={ !social.website.startsWith('http') ? `http://${social.website}` : social.website } /> )} {social?.skype && ( } title="Skype" value={social.skype} link={`skype:${social.skype}?chat`} /> )} {social?.telegram && ( } title="Telegram" value={social.telegram} link={`https://t.me/${social.telegram}`} /> )} {social?.phone && ( } title="Phone:" value={social.phone} link={`tel:${social.phone}`} /> )} {social?.email && ( } title="Email:" value={social.email} link={`mailto:${social.email}`} /> )} )}
); }; export default DetailsCard;