Skip to content

Commit d6093ee

Browse files
committed
🕴 t o o l s
1 parent 746b0e9 commit d6093ee

12 files changed

+63
-53
lines changed

components/AppMenuDrawer.fixture.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { createFixture } from 'react-cosmos';
44
import AppMenuDrawer from './AppMenuDrawer';
5-
import data from '../data';
5+
import data from '../tools/data';
66

77
const [user] = data.users;
88

components/AppMenuDrawer.js

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
// @flow
22

33
import * as React from 'react';
4-
import Link from './Link';
54
import styled from 'styled-components';
65
import { Spring, Trail } from 'react-spring';
7-
import type { User } from '../data/types';
6+
import Link from './Link';
7+
import { linksList } from '../tools/links';
8+
import firstName from '../tools/firstName';
9+
import type { User } from '../tools/types';
810

911
type Props = {
1012
open: boolean,
1113
selectedUser: User,
1214
};
1315

14-
const links = [
15-
{ href: '/', name: 'Home' },
16-
{ href: '/place', name: 'Places' },
17-
{ href: '/group', name: 'Group Trips' },
18-
];
19-
2016
export default class AppMenuDrawer extends React.Component<Props> {
2117
render() {
2218
const { open, selectedUser } = this.props;
@@ -35,14 +31,14 @@ export default class AppMenuDrawer extends React.Component<Props> {
3531
<Trail
3632
from={{ opacity: 0 }}
3733
to={{ opacity: 1 }}
38-
keys={links.map(link => link.name)}
34+
keys={linksList.map(([href]) => href)}
3935
delay={100}
4036
>
41-
{links.map(link => styles => (
37+
{linksList.map(([href, name]) => styles => (
4238
<div style={styles}>
43-
<Link href={link.href} color="white">
39+
<Link href={href} color="white">
4440
{firstName(selectedUser.name)}
45-
's {link.name}
41+
's {name}
4642
</Link>
4743
</div>
4844
))}
@@ -54,11 +50,6 @@ export default class AppMenuDrawer extends React.Component<Props> {
5450
}
5551
}
5652

57-
function firstName(input: string): string {
58-
const lastIndex = input.lastIndexOf(' ');
59-
return input.substring(0, lastIndex);
60-
}
61-
6253
const Drawer = styled.div`
6354
transform-origin: 100% 0%;
6455
background: rgba(0, 0, 0, 0.8);

components/AppNavTransition.fixture.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

33
import { createFixture } from 'react-cosmos';
44
import AppNavTransition from './AppNavTransition';
5-
import data from '../data';
6-
import paths from '../data/paths';
5+
import data from '../tools/data';
6+
import { linksList } from '../tools/links';
77

88
const [user] = data.users;
99

10-
export default paths.map((path, index) =>
10+
export default linksList.map(([href, name], index) =>
1111
createFixture({
1212
component: AppNavTransition,
13-
name: 'route: ' + path.name,
13+
name: 'route: ' + name,
1414
props: {
15-
pathname: path.pathname,
15+
pathname: href,
1616
users: data.users,
1717
selectedUser: user,
1818
indexedUser: 0,
1919
addFollower: () => {},
2020
removeFollower: () => {},
2121
changeUser(number, fn) {
22-
fn()
22+
fn();
2323
},
2424
},
2525
})

components/AppNavTransition.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import IconBase from './IconBase';
88
import IconMail from './IconMail';
99
import IconMapPin from './IconMapPin';
1010
import IconCalendar from './IconCalendar';
11-
import type { User } from '../data/types';
11+
import type { User } from '../tools/types';
1212

1313
type Props = {
1414
users: Array<User>,

components/AppNavigation.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ import AppNavTransition from './AppNavTransition';
88
import AppStats from './AppStats';
99
import IconBase from './IconBase';
1010
import IconThreeDot from './IconThreeDot';
11-
12-
const pathnames = [
13-
{ pathname: '/', name: 'index' },
14-
{ pathname: '/place', name: 'place' },
15-
{ pathname: '/group', name: 'group' },
16-
];
11+
import links from '../tools/links';
1712

1813
class Header extends React.Component {
1914
state = {
@@ -78,15 +73,15 @@ class Header extends React.Component {
7873
pathname,
7974
} = this.props;
8075

81-
const pathPredicate = pathname => p => p.pathname === pathname;
76+
const pathPredicate = pathname => p => p.href === pathname;
8277

8378
return (
84-
<header className={pathnames.find(pathPredicate(pathname)).name}>
79+
<header className={links.find(pathPredicate(pathname)).name}>
8580
<TransitionGroup className="bk-img">
8681
<CSSTransition classNames="bk" key={pathname} timeout={400}>
8782
<div
8883
className={`header-img${1 +
89-
pathnames.findIndex(pathPredicate(pathname))}`}
84+
links.findIndex(pathPredicate(pathname))}`}
9085
/>
9186
</CSSTransition>
9287
</TransitionGroup>

components/AppStats.fixture.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { createFixture } from 'react-cosmos';
44
import AppStats from './AppStats';
5-
import data from '../data';
5+
import data from '../tools/data';
66

77
export default data.users.map(user =>
88
createFixture({

components/AppStats.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as React from 'react';
44
import styled from 'styled-components';
5-
import type { User } from '../data/types';
5+
import type { User } from '../tools/types';
66

77
type Props = {
88
selectedUser: User,

data/paths.js

-17
This file was deleted.

data/index.js tools/data.js

File renamed without changes.

tools/firstName.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default function firstName(input: string): string {
2+
const lastIndex = input.lastIndexOf(' ');
3+
return input.substring(0, lastIndex);
4+
}

tools/links.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @flow
2+
3+
// the following works, but is kind of useless in this case,
4+
// as I need a custom "verbose name" for each path
5+
// anyway that was my first time using babel macros,
6+
// this is... d o p e
7+
8+
// import preval from 'babel-plugin-preval/macro';
9+
// const paths: Array<{ pathname: string, name: string }> = preval`
10+
// const path = require('path');
11+
// const fs = require('fs');
12+
13+
// module.exports = fs.readdirSync(path.resolve('./pages'))
14+
// .filter(file => !file.includes('_'))
15+
// .map(pageFile => pageFile.slice(0,-3))
16+
// .map(name => ({
17+
// pathname: name === 'index' ? '/' : '/' + name,
18+
// name: name,
19+
// }));
20+
// `;
21+
22+
type Links = {|
23+
'/': string,
24+
'/place': string,
25+
'/group': string,
26+
|};
27+
28+
const links: Links = {
29+
'/': 'Home',
30+
'/place': 'Places',
31+
'/group': 'Group Trips',
32+
};
33+
34+
// see https://github.com/facebook/flow/issues/2221
35+
export const linksList: Array<any> = Object.entries(links);
36+
37+
export default links;

data/types.js tools/types.js

File renamed without changes.

0 commit comments

Comments
 (0)