import React, { useState, useEffect, useRef } from 'react'; import PropTypes from 'prop-types'; import { name } from 'country-emoji'; import { useParams } from '@remix-run/react'; import * as icons from '../util/icons'; export default function Person({ person }) { const url = new URL(person.url); const twitter = person.twitter ? `https://unavatar.io/x/${person.twitter.replace('@', '')}` : null; const website = `https://unavatar.io/${url.host}`; const unavatar = person.twitter ? `${twitter}?fallback=${website}&ttl=28d` : website; const [_, mastodonHandle, mastodonServer] = person.mastodon?.split('@') || []; const { tag: currentTag } = useParams(); return (
{person.name} { currentTarget.onerror = null; // prevents looping currentTarget.src = "/default.png"; }} loading="lazy" />

{person.name} {" "} {person.emoji}

{url.host} {url.pathname.replace(/\/$/, "")}

{person.description}

{person.country} {person.computer && ( {person.computer} )} {person.phone && ( {person.phone} )} {person.twitter && (
@ {person.twitter.replace("@", "")}
)} {/* If they have a bluesky, and no twitter/mastodon, show that */} {person.bluesky && !person.twitter && (
@ {person.bluesky.substring(1)}
)} {/* If they have a mastodon, and no twitter, show that */} {person.mastodon && !person.twitter && !person.bluesky && (
@ {mastodonHandle}
)} {/* If they have a bluesky, and no mastodon and no twitter, show that */} {person.bluesky && !person.mastodon && !person.twitter && (
@ {person.bluesky}
)}
); } Person.propTypes = { person: PropTypes.shape({ github: PropTypes.string, name: PropTypes.string, url: PropTypes.string, emoji: PropTypes.string, description: PropTypes.string, tags: PropTypes.arrayOf(PropTypes.string), country: PropTypes.string, computer: PropTypes.oneOf(['apple', 'windows', 'linux', 'bsd']), phone: PropTypes.oneOf(['iphone', 'android', 'windowsphone', 'flipphone']), twitter(props, propName, componentName) { if (!/^@?(\w){1,15}$/.test(props[propName])) { return new Error( `Invalid prop \`${propName}\` supplied to` + ` \`${componentName}\`. This isn't a legit Twitter handle.` ); } }, mastodon(props, propName, componentName) { if (!/^@(\w){1,30}@(\w)+\.(\w)+$/.test(props[propName])) { return new Error( `Invalid prop \`${propName}\` supplied to` + ` \`${componentName}\`. This isn't a legit Mastodon handle.` ); } }, bluesky(props, propName, componentName) { if (!/^(\w)+\.(\w)+\.(\w)+$/.test(props[propName])) { return new Error( `Invalid prop \`${propName}\` supplied to` + ` \`${componentName}\`. This isn't a legit Bluesky handle.` ); } }, }), };