WIP Frontend structure & authentication.

This commit is contained in:
Ahmed Bouhuolia
2020-02-17 00:15:07 +02:00
parent b3849e55e9
commit e5c78fe555
56 changed files with 3539 additions and 322 deletions

View File

@@ -0,0 +1,48 @@
import { createStore as createReduxStore, applyMiddleware, compose } from 'redux';
import thunkMiddleware from 'redux-thunk';
import monitorReducerEnhancer from 'store/enhancers/monitorReducer';
import loggerMiddleware from 'middleware/logger'
import rootReducer from 'store/reducers';
const createStore = (initialState = {}) => {
/**
|--------------------------------------------------
| Middleware Configuration
|--------------------------------------------------
*/
const middleware = [
thunkMiddleware,
loggerMiddleware,
];
/**
|--------------------------------------------------
| Store Enhancers
|--------------------------------------------------
*/
const enhancers = [
monitorReducerEnhancer,
];
let composeEnhancers = compose;
if (process.env.NODE_ENV === 'development') {
if (typeof window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ === 'function') {
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
}
}
/**
|--------------------------------------------------
| Store Instantiation and HMR Setup
|--------------------------------------------------
*/
const store = createReduxStore(
rootReducer,
initialState,
composeEnhancers(applyMiddleware(...middleware), ...enhancers)
);
store.asyncReducers = {};
return store;
};
export default createStore();

View File

@@ -0,0 +1,17 @@
const round = number => Math.round(number * 100) / 100
const monitorReducerEnhancer = createStore => (
reducer,
initialState,
enhancer
) => {
const monitoredReducer = (state, action) => {
const start = performance.now()
const newState = reducer(state, action)
const end = performance.now()
const diff = round(end - start)
console.log('reducer process time:', diff)
return newState
}
return createStore(monitoredReducer, initialState, enhancer)
}
export default monitorReducerEnhancer

View File

View File

@@ -0,0 +1,18 @@
import t from 'store/types';
export default function authentication(state = {}, action) {
switch(action.type) {
case t.LOGIN_SUCCESS:
return {
...state,
token: action.token,
}
case t.LOGOUT:
return {
...state,
token: '',
};
default:
return state;
}
}

View File

@@ -0,0 +1,10 @@
import { combineReducers } from 'redux';
// import accounts from './accounts';
import authentication from './authentication';
// import users from './users';
export default combineReducers({
authentication,
// users,
// accounts,
});

View File

View File

@@ -0,0 +1,9 @@
const ACTION = {
LOGIN_REQUEST: 'LOGIN_REQUEST',
LOGIN_SUCCESS: 'LOGIN_SUCCESS',
LOGIN_FAILURE: 'LOGIN_FAILURE',
LOGOUT: 'LOGOUT',
};
export default ACTION;

View File

@@ -0,0 +1,5 @@
import authentication from './authentication';
export default {
...authentication,
};