Initial commit

This commit is contained in:
Nix1304
2020-04-02 02:14:23 +03:00
commit 36cff8be53
73 changed files with 19938 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
enum ActionTypes {
SET_USER = 'SET_USER',
LOGOUT = 'LOGOUT',
ADD_NOTIFICATION = 'ADD_NOTIFICATION'
}
export default ActionTypes;
+18
View File
@@ -0,0 +1,18 @@
import ActionTypes from "./actionTypes";
import React from "react";
const setUser = (userData: UserType) => ({
type: ActionTypes.SET_USER,
payload: { userData }
});
const logout = () => ({
type: ActionTypes.LOGOUT
});
const addNotification = (notification: React.ReactNode) => ({
type: ActionTypes.ADD_NOTIFICATION,
payload: { notification }
});
export { setUser, logout,
addNotification };
+30
View File
@@ -0,0 +1,30 @@
import ActionTypes from "../actionTypes";
const initialState = {
authorized: false
};
type Action = {
type: string
payload: {
userData: UserType
}
}
export default (state = initialState, action: Action) => {
switch (action.type) {
case ActionTypes.SET_USER:
if(action.payload.userData) {
state = Object.assign({}, state, action.payload.userData);
state.authorized = true;
}
return state;
case ActionTypes.LOGOUT:
state = {
authorized: false
};
return state;
default:
return state
}
}
+6
View File
@@ -0,0 +1,6 @@
import {combineReducers} from "redux";
import currentUser from "./currentUser";
import notifications from "./notifications";
export default combineReducers({ currentUser, notifications })
+22
View File
@@ -0,0 +1,22 @@
import React from "react";
import ActionTypes from "../actionTypes";
const initialState: React.ReactNode[] = [];
type Action = {
type: string
payload: {
notification: React.ReactNode[]
}
}
export default (state = initialState, action: Action) => {
switch (action.type) {
case ActionTypes.ADD_NOTIFICATION: {
if(state.length === 3)
return [...state.slice(1), action.payload.notification];
return [...state, action.payload.notification];
}
default: return state;
}
}
+8
View File
@@ -0,0 +1,8 @@
import {createStore} from "redux";
import index from "./reducers";
import {composeWithDevTools} from "redux-devtools-extension";
const composeEnhancers = composeWithDevTools({
trace: true
});
export default createStore(index, composeEnhancers());