Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use functional components if lifecycle methods aren't needed #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 50 additions & 25 deletions src/components/About.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
import React from 'react';
import CSSTranstionGroup from 'react-addons-css-transition-group';

class AboutModal extends React.Component {
constructor(props) {
super(props);
}

render() {
return (
<div className="about" onClick={this.props.onBgClick}>
<div className="about-inner" onClick={evt => {evt.stopPropagation()}}>
<p>I'm using <a href="http://www.last.fm/">Last.fm</a>'s API to pull in my music listening history, where I've been tracking song plays since October 2007.</p>
<p>If any of the totals are looking weird, it's because Last.fm's API is occasionally a piece of crap.</p>
<p>Really though, the site is an opportunity for me to experiment and learn more about <a href="https://facebook.github.io/react/">React</a> and especially <a href="http://redux.js.org/">Redux</a>. It was developed and compiled with webpack, and styled with help from <a href="http://cssnext.io/">cssnext</a> and <a href="https://github.com/peterramsing/lost">Lost</a>.</p>
<p className="lower">
A <a href="http://smahr.net">smahr.net</a> project / <a href="https://github.com/essmahr/listening">Github</a>
</p>
</div>
<div className="about-close"><span>Close</span></div>
</div>
);
}
}
const AboutModal = ({ onBgClick }) => (
<div className="about" onClick={onBgClick}>
<div
className="about-inner"
onClick={evt => {
evt.stopPropagation();
}}
>
<p>
I'm using <a href="http://www.last.fm/">Last.fm</a>
's API to pull in my music listening history, where I've been tracking
song plays since October 2007.
</p>
<p>
If any of the totals are looking weird, it's because Last.fm's API is
occasionally a piece of crap.
</p>
<p>
Really though, the site is an opportunity for me to experiment and learn
more about <a href="https://facebook.github.io/react/">React</a> and
especially <a href="http://redux.js.org/">Redux</a>. It was developed
and compiled with webpack, and styled with help from{' '}
<a href="http://cssnext.io/">cssnext</a> and{' '}
<a href="https://github.com/peterramsing/lost">Lost</a>.
</p>
<p className="lower">
A <a href="http://smahr.net">smahr.net</a> project /{' '}
<a href="https://github.com/essmahr/listening">Github</a>
</p>
</div>
<div className="about-close">
<span>Close</span>
</div>
</div>
);

export default class About extends React.Component {
constructor(props) {
super(props);

this.state = {
modalOpen: false,
}
};
}

toggleModal() {
Expand Down Expand Up @@ -60,10 +74,21 @@ export default class About extends React.Component {
return (
<div>
<div className="button-container">
<button className="about-launch" onClick={this.toggleModal.bind(this)}>?</button>
<button
className="about-launch"
onClick={this.toggleModal.bind(this)}
>
?
</button>
</div>
<CSSTranstionGroup transitionName="modal" transitionEnterTimeout={300} transitionLeaveTimeout={300}>
{this.state.modalOpen ? <AboutModal onBgClick={this.closeModal.bind(this)}/> : null}
<CSSTranstionGroup
transitionName="modal"
transitionEnterTimeout={300}
transitionLeaveTimeout={300}
>
{this.state.modalOpen ? (
<AboutModal onBgClick={this.closeModal.bind(this)} />
) : null}
</CSSTranstionGroup>
</div>
);
Expand Down
18 changes: 7 additions & 11 deletions src/components/ListHeader.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import React from 'react';
import TimeSpanMenu from './TimeSpanMenu';

class ListHeader extends React.Component {
render() {
return (
<header className="section-header">
<h1 className="section-title">{this.props.title}</h1>
<TimeSpanMenu />
</header>
);
}
}
const ListHeader = ({ title }) => (
<header className="section-header">
<h1 className="section-title">{title}</h1>
<TimeSpanMenu />
</header>
);

ListHeader.propTypes = {
title: React.PropTypes.string.isRequired,
}
};

export default ListHeader;
36 changes: 19 additions & 17 deletions src/components/Menu.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import React from 'react';
import { Link, IndexLink } from 'react-router';

export default class Explore extends React.Component {
constructor(props) {
super(props);
}
const Menu = () => (
<nav className="menu-outer">
<div className="menu">
<IndexLink className="menu-link" activeClassName="active" to="/">
Recent
</IndexLink>
<Link className="menu-link" activeClassName="active" to="/artists">
Artists
</Link>
<Link className="menu-link" activeClassName="active" to="/albums">
Albums
</Link>
<Link className="menu-link" activeClassName="active" to="/tracks">
Tracks
</Link>
</div>
</nav>
);

render() {
return (
<nav className="menu-outer">
<div className="menu">
<IndexLink className="menu-link" activeClassName="active" to="/">Recent</IndexLink>
<Link className="menu-link" activeClassName="active" to="/artists">Artists</Link>
<Link className="menu-link" activeClassName="active" to="/albums">Albums</Link>
<Link className="menu-link" activeClassName="active" to="/tracks">Tracks</Link>
</div>
</nav>
);
}
}
export default Menu;
29 changes: 11 additions & 18 deletions src/components/NowPlaying.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import React from 'react';
import { Link } from 'react-router';
import SineWave from './SineWave';

export default class NowPlaying extends React.Component {
constructor(props) {
super(props);
}
export default ({ track }) => {
const { name, artist } = track;

render() {
const {name, artist} = this.props.track;

return (
<div className="now-playing">
<h5 className="now-playing-label">Listening:</h5>
<h1 className="now-playing-title">{name}</h1>
<h2 className="now-playing-artist">{artist.name}</h2>
<SineWave/>
</div>
);
}
}
return (
<div className="now-playing">
<h5 className="now-playing-label">Listening:</h5>
<h1 className="now-playing-title">{name}</h1>
<h2 className="now-playing-artist">{artist.name}</h2>
<SineWave />
</div>
);
};
24 changes: 8 additions & 16 deletions src/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@ import Header from '../containers/Header';
import About from '../components/About';
import LoaderWrapper from '../components/LoaderWrapper';

class App extends React.Component {
constructor(props) {
super(props);
}

render() {
return (
<LoaderWrapper>
<Header/>
{this.props.children}
<About/>
</LoaderWrapper>
);
}
}
const App = props => (
<LoaderWrapper>
<Header />
{props.children}
<About />
</LoaderWrapper>
);

App.propTypes = {
children: React.PropTypes.node
children: React.PropTypes.node,
};

export default App;
26 changes: 13 additions & 13 deletions src/containers/Root.dev.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import React, { Component, PropTypes } from 'react';
import React, { PropTypes } from 'react';
import { Provider } from 'react-redux';
import routes from '../routes';
import DevTools from './DevTools';
import { Router } from 'react-router';

export default class Root extends Component {
render() {
const { store, history } = this.props
return (
<Provider store={store}>
<div>
<Router history={history} routes={routes} />
<DevTools />
</div>
</Provider>
)
}
const Root = props => {
const { store, history } = props
return (
<Provider store={store}>
<div>
<Router history={history} routes={routes} />
<DevTools />
</div>
</Provider>
)
};

Root.propTypes = {
store: PropTypes.object.isRequired,
history: PropTypes.object.isRequired
};

export default Root;
20 changes: 10 additions & 10 deletions src/containers/Root.prod.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component, PropTypes } from 'react';
import React, { PropTypes } from 'react';
import { Provider } from 'react-redux';
import routes from '../routes';
import { Router } from 'react-router';
Expand All @@ -10,18 +10,18 @@ function logPageView() {
ga.pageview(window.location.pathname);
}

export default class Root extends Component {
render() {
const { store, history } = this.props;
return (
<Provider store={store}>
<Router history={history} routes={routes} onUpdate={logPageView}/>
</Provider>
);
}
const Root = props => {
const { store, history } = props;
return (
<Provider store={store}>
<Router history={history} routes={routes} onUpdate={logPageView}/>
</Provider>
);
}

Root.propTypes = {
store: PropTypes.object.isRequired,
history: PropTypes.object.isRequired
};

export default Root;