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

Split code header component #118

Open
wants to merge 6 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 3 additions & 9 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"presets": [
"es2015",
"react",
"stage-2"
],
"plugins": [
"react-hot-loader/babel"
]
}
"presets": ["es2015", "react", "stage-2"],
"plugins": ["transform-decorators-legacy", "react-hot-loader/babel"]
}
13 changes: 8 additions & 5 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<!DOCTYPE html>
<html>

<head>
<title>FaveSound</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<title>FaveSound</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
</head>

<body>
<div id="app"></div>
<script src="/bundle.js"></script>
<div id="app"></div>
<script src="/bundle.js"></script>
</body>
</html>

</html>
5 changes: 5 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"experimentalDecorators": true
}
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"babel-core": "6.3.15",
"babel-eslint": "7.1.1",
"babel-loader": "6.2.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "6.3.13",
"babel-preset-react": "6.3.13",
"babel-preset-stage-2": "6.5.0",
Expand All @@ -32,6 +33,7 @@
"eslint-plugin-jsx-a11y": "2.2.3",
"eslint-plugin-react": "6.7.1",
"exports-loader": "^0.6.4",
"file-loader": "^1.1.11",
"imports-loader": "^0.6.5",
"jsdom": "9.8.3",
"mocha": "3.5.3",
Expand All @@ -53,9 +55,10 @@
"moment": "2.18.1",
"normalizr": "2.0.0",
"prop-types": "15.5.10",
"react": "16.0.0",
"react": "^16.3.2",
"react-clipboard.js": "1.1.2",
"react-dom": "16.0.0",
"react-dom": "^16.3.2",
"react-favicon": "^0.0.14",
"react-rangeslider": "2.1.0",
"react-redux": "5.0.6",
"react-router": "4.1.1",
Expand Down
Binary file added src/assets/btn-connect-m.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/btn-disconnect-m.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/sc_ico.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/soundcloud.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 19 additions & 30 deletions src/components/App/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import React from 'react';
import { BrowserRouter, Route, Switch, Redirect } from 'react-router-dom';
import { OAUTH_TOKEN } from '../../constants/authentication';
import Cookies from 'js-cookie';
import { DEFAULT_GENRE } from '../../constants/genre';
import Browse from '../../components/Browse';
import Callback from '../../components/Callback';
import Dashboard from '../../components/Dashboard';
import Header from '../../components/Header';
import Player from '../../components/Player';
import Playlist from '../../components/Playlist';
import Volume from '../../components/Volume';
import { browse, dashboard, callback } from '../../constants/pathnames';
import Cookies from "js-cookie";
import React, { Component, Fragment } from "react";

export default class App extends React.Component {
import Header from "../Header";
import Player from "../Player";
import Volume from "../Volume";
import Router from "../Router";
import Playlist from "../Playlist";
import { OAUTH_TOKEN } from "../../constants/authentication";

export default class App extends Component {
constructor(props) {
super(props);
this.onAppClose = this.onAppClose.bind(this);
}

componentDidMount() {
window.addEventListener('beforeunload', this.onAppClose);
window.addEventListener("beforeunload", this.onAppClose);
}

componentWillUnmount() {
window.removeEventListener('beforeunload', this.onAppClose);
window.removeEventListener("beforeunload", this.onAppClose);
}

onAppClose() {
Expand All @@ -32,20 +28,13 @@ export default class App extends React.Component {

render() {
return (
<BrowserRouter>
<div>
<Header />
<Switch>
<Route exact path={`${browse}/:genre`} component={Browse} />
<Route exact path={dashboard} component={Dashboard} />
<Route exact path={callback} component={Callback} />
<Redirect to={`${browse}/${DEFAULT_GENRE}`} />
</Switch>
<Playlist />
<Volume />
<Player />
</div>
</BrowserRouter>
<Fragment>
<Header />
<Router />
<Playlist />
<Volume />
<Player />
</Fragment>
);
}
}
129 changes: 8 additions & 121 deletions src/components/Header/index.js
Original file line number Diff line number Diff line change
@@ -1,132 +1,19 @@
import PropTypes from 'prop-types';
import React from 'react';
import map from '../../services/map';
import classNames from 'classnames';
import { Link } from 'react-router-dom';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import React from "react";

import * as actions from '../../actions/index';
import { GENRES, DEFAULT_GENRE } from '../../constants/genre';
import { browse, dashboard } from '../../constants/pathnames';
import Logo from "../Logo";
import MenuList from "../MenuList";
import SessionAction from "../SessionAction";

function getGenreLink(genre) {
return `${browse}/${genre || DEFAULT_GENRE}`;
}

function Logo() {
return (
<div>
<div className="logo">
<Link to="/">
<h1>Favesound</h1>
</Link>
</div>
<div className="github-link">
<Link to="https://github.com/rwieruch/favesound-redux/" target="_blank">
<p>Fork Me on Github</p>
</Link>
</div>
</div>
);
}

function MenuItem({ genre, selectedGenre }) {
const linkClass = classNames('menu-item', {
'menu-item-selected': genre === selectedGenre,
});

return (
<Link to={getGenreLink(genre)} className={linkClass}>
{genre}
</Link>
);
}

function Login({ onLogin }) {
return (
<Link onClick={onLogin} to={dashboard}>
Login
</Link>
);
}

function Logout({ onLogout }) {
return (
<Link onClick={onLogout} to={browse}>
Logout
</Link>
);
}

function Dashboard({ onDashboard }) {
return (
<Link onClick={onDashboard} to={dashboard}>
Dashboard
</Link>
);
}

function SessionAction({ currentUser, onLogin, onLogout, onDashboard }) {
return (
<div>
<div className="dashboard-link">
{ currentUser ? <Dashboard onDashboard={onDashboard} /> : ' ' }
</div>
<div className="session-link">
{ currentUser ? <Logout onLogout={onLogout} /> : <Login onLogin={onLogin} /> }
</div>
</div>
);
}

function MenuList({ selectedGenre }) {
if (!selectedGenre) return null;
return (
<div>
{map((genre, key) => {
const menuItemProps = { genre, selectedGenre, key };
return <MenuItem {...menuItemProps} />;
}, GENRES)}
</div>
);
}

function Header({ currentUser, selectedGenre, onLogin, onLogout, onDashboard }) {
const Header = () => {
return (
<div className="header">
<div className="header-content">
<Logo />
<MenuList selectedGenre={selectedGenre} />
<SessionAction
currentUser={currentUser}
onLogin={onLogin}
onLogout={onLogout}
onDashboard={onDashboard}
/>
<MenuList />
<SessionAction />
</div>
</div>
);
}

function mapStateToProps(state) {
return {
currentUser: state.session.user,
selectedGenre: state.browse.selectedGenre
};
}

function mapDispatchToProps(dispatch) {
return {
onLogin: bindActionCreators(actions.login, dispatch),
onLogout: bindActionCreators(actions.logout, dispatch),
};
}

Header.propTypes = {
currentUser: PropTypes.object,
onLogin: PropTypes.func,
onLogout: PropTypes.func,
};

export default connect(mapStateToProps, mapDispatchToProps)(Header);
export default Header;
25 changes: 25 additions & 0 deletions src/components/Logo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { Fragment } from "react";
import { Link } from "react-router-dom";

import logo from "../../assets/soundcloud.png";

const Logo = () => (
<Fragment>
<div className="logo">
<Link to="/">
<img src={logo} alt="FaveSound" />
<h1>FaveSound</h1>
</Link>
</div>
<div className="github-link">
<Link to="https://github.com/rwieruch/favesound-redux" target="_blank">
<img
src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png"
alt="Fork me on GitHub"
/>
</Link>
</div>
</Fragment>
);

export default Logo;
30 changes: 30 additions & 0 deletions src/components/MenuItem/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
import { Link } from "react-router-dom";

import { browse } from "../../constants/pathnames";
import { DEFAULT_GENRE } from "../../constants/genre";

const MenuItem = ({ genre, selectedGenre }) => {
const linkClass = classNames("menu-item", {
"menu-item-selected": genre === selectedGenre
});

return (
<Link to={getGenreLink(genre)} className={linkClass}>
{genre}
</Link>
);
};

function getGenreLink(genre) {
return `${browse}/${genre || DEFAULT_GENRE}`;
}

MenuItem.propTypes = {
genre: PropTypes.string.isRequired,
selectedGenre: PropTypes.string.isRequired
};

export default MenuItem;
39 changes: 39 additions & 0 deletions src/components/MenuList/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import PropTypes from "prop-types";
import { connect } from "react-redux";
import React, { Component } from "react";

import MenuItem from "../MenuItem";
import map from "../../services/map";
import { GENRES } from "../../constants/genre";

function mapStateToProps(state) {
return {
selectedGenre: state.browse.selectedGenre
};
}

@connect(mapStateToProps)
class MenuList extends Component {
render() {
const { selectedGenre } = this.props;

if (!selectedGenre) {
return null;
}

return (
<div className="menu">
{map((genre, key) => {
const menuItemProps = { genre, selectedGenre, key };
return <MenuItem {...menuItemProps} />;
}, GENRES)}
</div>
);
}
}

MenuList.propTypes = {
selectedGenre: PropTypes.string
};

export default MenuList;
19 changes: 19 additions & 0 deletions src/components/Router/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";
import { Route, Switch, Redirect } from "react-router-dom";

import Browse from "../Browse";
import Callback from "../Callback";
import Dashboard from "../Dashboard";
import { DEFAULT_GENRE } from "../../constants/genre";
import { browse, dashboard, callback } from "../../constants/pathnames";

const Router = () => (
<Switch>
<Route exact path={`${browse}/:genre`} component={Browse} />
<Route exact path={dashboard} component={Dashboard} />
<Route exact path={callback} component={Callback} />
<Redirect to={`${browse}/${DEFAULT_GENRE}`} />
</Switch>
);

export default Router;