Skip to content

Commit

Permalink
src: better redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed May 15, 2020
1 parent c3be847 commit 0a3bae7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 19 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@
},
"devDependencies": {
"concurrently": "^5.2.0",
"connected-react-router": "^6.8.0",
"electron": "^8.3.0",
"electron-builder": "^22.6.0",
"emoji-mart": "^3.0.0",
"eslint": "^6.8.0",
"eslint-plugin-react": "^7.20.0",
"history": "^4.10.1",
"moment": "^2.25.3",
"react": "^16.13.1",
"react-dom": "^16.13.1",
Expand Down
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, compose, applyMiddleware } from 'redux';
import logger from 'redux-logger';
import thunk from 'redux-thunk';
import { ConnectedRouter } from 'connected-react-router';

import './index.css';
import App from './App';
import reducer from './redux/reducers';
import createStore from './redux/store';

const store = createStore(reducer, compose(applyMiddleware(thunk, logger)));
const { store, history } = createStore();

ReactDOM.render(<Provider store={store}>
<App/>
<ConnectedRouter history={history}>
<App/>
</ConnectedRouter>
</Provider>, document.getElementById('root'));
4 changes: 3 additions & 1 deletion src/redux/actions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { push as routerPush } from 'connected-react-router';

import { getFeedURL } from '../utils';

import Network from './network';
Expand Down Expand Up @@ -44,7 +46,7 @@ export const CHANNEL_SET_CHAIN_MAP = 'CHANNEL_SET_CHAIN_MAP';
const network = new Network();

export function setRedirect(to) {
console.error('TODO(indutny): implement me');
return routerPush(to);
}

export function setFocus(focus) {
Expand Down
31 changes: 19 additions & 12 deletions src/redux/reducers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { combineReducers } from 'redux';
import { connectRouter } from 'connected-react-router';

import { appendMessage, computeIdentityFilter } from './utils';

Expand Down Expand Up @@ -507,17 +508,23 @@ export const channels = (state = new Map(), action) => {
}
};

export default combineReducers({
focus,
compose,
const createRootReducer = (history) => {
return combineReducers({
router: connectRouter(history),

// Various asynchronous states
network,
newChannel,
inviteRequest,
notifications,
focus,
compose,

identities,
identityFilter,
channels,
});
// Various asynchronous states
network,
newChannel,
inviteRequest,
notifications,

identities,
identityFilter,
channels,
});
};

export default createRootReducer;
17 changes: 17 additions & 0 deletions src/redux/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createHashHistory as createHistory } from 'history';
import { applyMiddleware, compose, createStore } from 'redux';
import { routerMiddleware } from 'connected-react-router';
import logger from 'redux-logger';
import thunk from 'redux-thunk';

import createRootReducer from './reducers';

export default () => {
const history = createHistory();

const store = createStore(
createRootReducer(history),
compose(applyMiddleware(routerMiddleware(history), thunk, logger)))

return { store, history };
};

0 comments on commit 0a3bae7

Please sign in to comment.