Merge branch 'website' into website

This commit is contained in:
Wes Bos 2020-01-08 10:54:21 -05:00 committed by GitHub
commit db1be405de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 115 deletions

View file

@ -1,5 +1,5 @@
import people from './src/data.js'; import people from './src/data.js';
import { tags, countries, computers, phones } from './src/util/stats'; import { tags, countries, devices } from './src/util/stats';
function sourceNodes({ actions, createNodeId, createContentDigest }) { function sourceNodes({ actions, createNodeId, createContentDigest }) {
// Add People to the GraphQL API, we randomize the data on each build so no one gets their feelings hurt // Add People to the GraphQL API, we randomize the data on each build so no one gets their feelings hurt
@ -55,36 +55,21 @@ function sourceNodes({ actions, createNodeId, createContentDigest }) {
actions.createNode({ ...country, ...nodeMeta }); actions.createNode({ ...country, ...nodeMeta });
}); });
// Add Computers to GraphQL API // Add Devices to GraphQL API
computers().forEach(computer => { console.log(devices());
devices().forEach(device => {
const nodeMeta = { const nodeMeta = {
id: createNodeId(`computer-${computer.name}`), id: createNodeId(`device-${device.name}`),
parent: null, parent: null,
children: [], children: [],
internal: { internal: {
type: `Computer`, type: `device`,
mediaType: `text/html`, mediaType: `text/html`,
content: JSON.stringify(computer), content: JSON.stringify(device),
contentDigest: createContentDigest(computer), contentDigest: createContentDigest(device),
}, },
}; };
actions.createNode({ ...computer, ...nodeMeta }); actions.createNode({ ...device, ...nodeMeta });
});
// Add Phones to GraphQL API
phones().forEach(phone => {
const nodeMeta = {
id: createNodeId(`phone-${phone.name}`),
parent: null,
children: [],
internal: {
type: `Phone`,
mediaType: `text/html`,
content: JSON.stringify(phone),
contentDigest: createContentDigest(phone),
},
};
actions.createNode({ ...phone, ...nodeMeta });
}); });
} }

View file

@ -3,14 +3,9 @@ import styled from 'styled-components';
import FilterContext from '../context/FilterContext'; import FilterContext from '../context/FilterContext';
export default function Topics() { export default function Topics() {
const { const { countries, tags, devices, currentTag, setCurrentTag } = useContext(
countries, FilterContext
tags, );
phones,
computers,
currentTag,
setCurrentTag,
} = useContext(FilterContext);
return ( return (
<Tags> <Tags>
@ -53,9 +48,9 @@ export default function Topics() {
</Tag> </Tag>
))} ))}
{computers.map(tag => ( {devices.map(tag => (
<label <Tag
className={`tag ${tag.name === currentTag ? 'currentTag' : ''}`} currentTag={tag.name === currentTag}
htmlFor={`filter-${tag.name}`} htmlFor={`filter-${tag.name}`}
key={`filter-${tag.name}`} key={`filter-${tag.name}`}
title={tag.name} title={tag.name}
@ -69,27 +64,8 @@ export default function Topics() {
onChange={e => setCurrentTag(e.currentTarget.value)} onChange={e => setCurrentTag(e.currentTarget.value)}
/> />
{tag.name} {tag.name}
<span className="count">{tag.count}</span> <TagCount>{tag.count}</TagCount>
</label> </Tag>
))}
{phones.map(tag => (
<label
className={`tag ${tag.name === currentTag ? 'currentTag' : ''}`}
htmlFor={`filter-${tag.name}`}
key={`filter-${tag.name}`}
title={tag.name}
>
<input
type="radio"
name="tag"
id={`filter-${tag.name}`}
value={tag.name}
checked={tag.name === currentTag}
onChange={e => setCurrentTag(e.currentTarget.value)}
/>
{tag.name}
<span className="count">{tag.count}</span>
</label>
))} ))}
</Tags> </Tags>
); );

View file

@ -6,7 +6,7 @@ const FilterContext = createContext();
const FilterProvider = function({ children }) { const FilterProvider = function({ children }) {
const [currentTag, setCurrentTag] = useState('all'); const [currentTag, setCurrentTag] = useState('all');
const { allTag, allCountry, allComputer, allPhone } = useStaticQuery(graphql` const { allTag, allCountry, allDevice } = useStaticQuery(graphql`
query FilterQuery { query FilterQuery {
allTag { allTag {
nodes { nodes {
@ -21,13 +21,7 @@ const FilterProvider = function({ children }) {
name name
} }
} }
allComputer { allDevice {
nodes {
count
name
}
}
allPhone {
nodes { nodes {
count count
name name
@ -40,8 +34,7 @@ const FilterProvider = function({ children }) {
value={{ value={{
tags: allTag.nodes, tags: allTag.nodes,
countries: allCountry.nodes, countries: allCountry.nodes,
computers: allComputer.nodes, devices: allDevice.nodes,
phones: allPhone.nodes,
currentTag, currentTag,
setCurrentTag, setCurrentTag,
}} }}

View file

@ -490,8 +490,7 @@ const pages = [
}, },
{ {
name: 'Timothy Miller', name: 'Timothy Miller',
description: description: 'Web Designer/Developer for hire. Wears lots of hats.',
'Web Designer/Developer for hire. Wears lots of hats.',
url: 'https://timothymiller.dev/uses', url: 'https://timothymiller.dev/uses',
twitter: '@WebInspectInc', twitter: '@WebInspectInc',
emoji: '🥓', emoji: '🥓',
@ -510,7 +509,30 @@ const pages = [
'PHP', 'PHP',
'Blogger' 'Blogger'
], ],
} },
{
name: 'Tim Dorr',
description: 'Founder of Spaceship and SalesLoft. Maintainer of Redux and React Router. Dad, husband, and all-around nerd.',
url: 'https://timdorr.com/',
twitter: '@timdorr',
emoji: '🤘',
country: '🇺🇸',
computer: 'apple',
phone: 'android',
tags: [
'Developer',
'Full Stack',
'Entrepreneur',
'Investor',
'JavaScript',
'TypeScript',
'Ruby',
'Go',
'Elixir',
'Swift',
'React',
],
},
]; ];
export default pages; export default pages;

0
src/util/icons.js Normal file
View file

View file

@ -50,52 +50,13 @@ export function tags() {
return [{ name: 'all', count: people.length }, ...tags]; return [{ name: 'all', count: people.length }, ...tags];
} }
export function computers() { export function devices() {
const data = people const all = [
.map(person => ({ ...people.map(person => person.computer),
name: person.computer, ...people.map(person => person.phone),
})) ];
.reduce((acc, computer) => {
if (acc[computer.name]) {
// exists, update
acc[computer.name].count += 1;
} else {
acc[computer.name] = {
...computer,
count: 1,
};
}
return acc;
}, {});
const sorted = Object.entries(data) return Object.entries(all.reduce(countInstances, {}))
.map(([, computer]) => computer) .map(([device, count]) => ({ name: device, count }))
.sort((a, b) => b.count - a.count); .sort((a, b) => b.count - a.count);
return sorted;
}
export function phones() {
const data = people
.map(person => ({
name: person.phone,
}))
.reduce((acc, phone) => {
if (acc[phone.name]) {
// exists, update
acc[phone.name].count = acc[phone.name].count + 1;
} else {
acc[phone.name] = {
...phone,
count: 1,
};
}
return acc;
}, {});
const sorted = Object.entries(data)
.map(([, phone]) => phone)
.sort((a, b) => b.count - a.count);
return sorted;
} }