Skip to content

Commit b73c7fc

Browse files
committed
Finish versions upgrade
1 parent 72be9ed commit b73c7fc

File tree

7 files changed

+207
-293
lines changed

7 files changed

+207
-293
lines changed

client/components/App.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
import React, { Component } from 'react';
2+
import { Route, Switch } from 'react-router-dom';
3+
import User from "./User";
4+
import Login from "./Login";
5+
import Error from "./Error";
26

37
/**
48
* Main app component
59
* Has a header and then render's the page content
610
*/
711
export default class SpotifyLogin extends Component {
12+
13+
constructor (props){
14+
super(props);
15+
}
16+
817
render() {
9-
// injected via react router
10-
const {children} = this.props;
1118
return (
1219
<div className="spotify-login">
1320
<h1>Example Spotify + React + React-Router Login Flow</h1>
1421
<div className="page-content">
1522
<p>This is an example of the Authorization Code flow using routes.</p>
16-
{children}
23+
<Switch>
24+
<Route exact path="/user/:accessToken/:refreshToken" component={User} />
25+
<Route exact path="/error/:errorMsg" component={Error} />
26+
<Route exact path="/" component={Login} />
27+
</Switch>
1728
</div>
1829
</div>
1930
);

client/components/Error.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ import React, { Component } from 'react';
55
* Displays the error
66
*/
77
export default class Login extends Component {
8+
9+
constructor (props){
10+
super(props);
11+
}
12+
813
render() {
914
// injected via react-router
10-
const { errorMsg } = this.props.params;
15+
const { errorMsg } = this.props.match.params;
1116
return (
1217
<div className="error">
1318
<h2>An Error Occured</h2>

client/components/Login.js

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import loginSVG from '../log_in.svg';
66
* Has a login button that hit's the login url
77
*/
88
export default class Login extends Component {
9+
10+
constructor (props){
11+
super(props);
12+
}
13+
914
render() {
1015
return (
1116
<div className="login">

client/components/User.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ import {
1010
* Displays the user's information
1111
*/
1212
class User extends Component {
13+
14+
constructor (props){
15+
super(props);
16+
}
17+
1318
/** When we mount, get the tokens from react-router and initiate loading the info */
1419
componentDidMount() {
1520
// params injected via react-router, dispatch injected via connect
16-
const {dispatch, params} = this.props;
17-
const {accessToken, refreshToken} = params;
21+
const {dispatch, match} = this.props;
22+
const {accessToken, refreshToken} = match.params;
1823
dispatch(setTokens({accessToken, refreshToken}));
1924
dispatch(getMyInfo());
2025
}

client/index.js

+13-20
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,33 @@
11
import React, { Component } from 'react';
22
import { render } from 'react-dom';
3-
import { createStore, combineReducers, applyMiddleware } from 'redux';
3+
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
44
import thunk from 'redux-thunk';
55
import { Provider } from 'react-redux';
6-
import { Router, Route, IndexRoute, hashHistory } from 'react-router';
7-
import { syncHistory, routeReducer } from 'react-router-redux';
8-
import { createHistory } from 'history';
6+
import { Route } from 'react-router-dom';
7+
import createHashHistory from 'history/createHashHistory';
8+
import { ConnectedRouter, routerReducer, routerMiddleware } from 'react-router-redux';
99
import reducer from './reducers';
1010
import App from './components/App';
11-
import Login from './components/Login';
12-
import User from './components/User';
13-
import Error from './components/Error';
1411

1512
// load our css. there probably is a better way to do this
1613
// but for now this is our move
1714
require('./style.less');
1815

1916
// Sync dispatched route actions to the history
20-
const reduxRouterMiddleware = syncHistory(hashHistory)
21-
const createStoreWithMiddleware = applyMiddleware(
22-
thunk,
23-
reduxRouterMiddleware
24-
)(createStore)
25-
const store = createStoreWithMiddleware(reducer)
17+
const hashHistory = createHashHistory();
18+
19+
const store = createStore(reducer, undefined, compose(
20+
applyMiddleware(thunk, routerMiddleware(history)),
21+
window.devToolsExtension ? window.devToolsExtension() : f => f,
22+
));
2623

2724
class Root extends Component {
2825
render() {
2926
return (
3027
<Provider store={store}>
31-
<Router history={hashHistory}>
32-
<Route path="/" component={App}>
33-
<IndexRoute component={Login} />
34-
<Route path="/user/:accessToken/:refreshToken" component={User} />
35-
<Route path="/error/:errorMsg" component={Error} />
36-
</Route>
37-
</Router>
28+
<ConnectedRouter history={hashHistory}>
29+
<Route path="/" component={App}/>
30+
</ConnectedRouter>
3831
</Provider>
3932
);
4033
}

0 commit comments

Comments
 (0)