awesome-uses/src/components/Person.js

107 lines
3.3 KiB
JavaScript
Raw Normal View History

2020-01-22 17:14:25 +00:00
import React, { useState, useEffect, useRef } from 'react';
2020-01-08 16:25:18 +00:00
import PropTypes from 'prop-types';
2020-01-07 20:23:53 +00:00
import { name } from 'country-emoji';
2020-01-08 16:06:32 +00:00
import * as icons from '../util/icons';
2023-02-20 20:41:29 +00:00
import { useParams } from '@remix-run/react';
2020-01-07 20:23:53 +00:00
2023-02-20 20:41:29 +00:00
export default function Person({ person }) {
2020-01-07 20:23:53 +00:00
const url = new URL(person.url);
2023-01-09 19:12:22 +00:00
const twitter = person.twitter ? `https://unavatar.io/${person.twitter.replace('@', '')}` : null;
2023-01-09 19:05:02 +00:00
const website = `https://unavatar.io/${url.host}`;
const unavatar = person.twitter ? `${twitter}?fallback=${website}` : website;
const img = `https://images.weserv.nl/?url=${unavatar}&w=100&l=9&af&il&n=-1`;
2023-02-20 20:41:29 +00:00
const { tag: currentTag } = useParams();
2020-01-07 20:23:53 +00:00
return (
2023-02-25 16:01:47 +00:00
<div className="PersonWrapper" style={{ contentVisibility: "auto", containIntrinsicHeight: '560px' }}>
2023-02-20 20:41:29 +00:00
<div className="PersonInner">
2020-01-07 22:58:15 +00:00
<header>
2020-01-30 20:04:30 +00:00
<img
width="50"
height="50"
src={img}
alt={person.name}
loading="lazy"
/>
2020-01-07 21:38:31 +00:00
<h3>
<a href={person.url} target="_blank" rel="noopener noreferrer">
{person.name}
</a>{' '}
{person.emoji}
2020-01-07 21:38:31 +00:00
</h3>
<a
2020-01-10 15:12:12 +00:00
target="_blank"
rel="noopener noreferrer"
2020-01-07 21:38:31 +00:00
className="displayLink"
href={person.url}
2020-01-17 20:40:06 +00:00
>
{url.host}
{url.pathname.replace(/\/$/, '')}
</a>
2020-01-07 21:38:31 +00:00
</header>
2020-01-07 20:23:53 +00:00
<p>{person.description}</p>
2023-02-20 20:41:29 +00:00
<ul className="Tags">
2020-01-07 20:23:53 +00:00
{person.tags.map(tag => (
2023-02-20 20:41:29 +00:00
<li className={`Tag small ${tag === currentTag ? 'currentTag' : ''}`} key={tag}>
2020-01-07 20:23:53 +00:00
{tag}
2023-02-20 20:41:29 +00:00
</li>
2020-01-07 20:23:53 +00:00
))}
2023-02-20 20:41:29 +00:00
</ul>
</div>
<div className="PersonDeets">
2020-01-07 20:23:53 +00:00
<span className="country" title={name(person.country)}>
{person.country}
</span>
{person.computer && (
<span title={`Computer: ${person.computer}`}>
<img
height="40"
src={icons[person.computer]}
alt={person.computer}
/>
</span>
)}
{person.phone && (
<span title={`Uses an ${person.phone}`}>
<img height="50" src={icons[person.phone]} alt={person.phone} />
</span>
)}
{person.twitter && (
2023-02-20 20:41:29 +00:00
<div className="TwitterHandle">
2020-01-07 21:07:32 +00:00
<a
href={`https://twitter.com/${person.twitter.replace('@', '')}`}
2020-01-07 21:07:32 +00:00
target="_blank"
rel="noopener noreferrer"
>
2020-01-07 20:23:53 +00:00
<span className="at">@</span>
{person.twitter.replace('@', '')}
</a>
2023-02-20 20:41:29 +00:00
</div>
2020-01-07 20:23:53 +00:00
)}
2023-02-20 20:41:29 +00:00
</div>
</div>
2020-01-07 20:23:53 +00:00
);
}
2020-01-07 22:58:15 +00:00
2020-01-08 16:25:18 +00:00
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,
2020-01-08 16:25:18 +00:00
computer: PropTypes.oneOf(['apple', 'windows', 'linux']),
2023-02-20 20:41:29 +00:00
phone: PropTypes.oneOf(['iphone', 'android', 'windowsphone', 'flipphone']),
2020-01-08 16:25:18 +00:00
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.`
);
}
},
}),
};