Sfoglia il codice sorgente

login preparation, new store added

pocu46 3 anni fa
parent
commit
bcea3a8ba6

+ 1 - 2
hipstagram/src/Content/Login/Login.js

@@ -1,6 +1,5 @@
 import React from 'react';
 import { NavLink } from 'react-router-dom';
-import Registration from '../Registration/Registration.js';
 import './Login.css';
 
 const Login = () => {
@@ -12,7 +11,7 @@ const Login = () => {
             <button>Login</button>
 
             <nav>
-                {/* <NavLink href={Registration} >Registration</NavLink> */}
+                <NavLink to="/registration" >Registration</NavLink>
             </nav>
         </div>
     )

+ 1 - 2
hipstagram/src/Content/Registration/Registration.js

@@ -1,6 +1,5 @@
 import React from 'react';
 import { NavLink } from 'react-router-dom';
-import Login from '../Login/Login';
 import './Registration.css';
 
 const Registration = () => {
@@ -13,7 +12,7 @@ const Registration = () => {
             <button>Registration</button>
 
             <nav>
-                <NavLink href={Login}>Login</NavLink>
+                <NavLink to="/login">Login</NavLink>
             </nav>
         </div>
     )

+ 0 - 0
hipstagram/src/Redux/login_reducer.js


+ 55 - 0
hipstagram/src/Redux/promise_reducer.js

@@ -0,0 +1,55 @@
+import { createStore, combineReducers, applyMiddleware } from "redux";
+import thunk from 'redux-thunk';
+
+const authReducer = (state, action) => {
+    // if(action.type===)
+}
+const promiseReducer = (state, action) => {
+    if (action.type === 'LOGIN' || action.type === 'LOGOUT') {
+        return {}
+    }
+    if (action.type === 'PROMISE') {
+        return
+    }
+    return state
+}
+const actionPromise = (name, promise) => {
+    const actionPending = () => ({
+        type: 'PROMISE',
+        name,
+        status: 'PENDING',
+        payload: null,
+        error: null
+    })
+    const actionResolved = (payload) => ({
+        type: 'PROMISE',
+        name,
+        status: 'RESOLVED',
+        payload,
+        error: null
+    })
+    const actionRejected = (error) => ({
+        type: 'PROMISE',
+        name,
+        status: 'REJECTED',
+        payload: null,
+        error
+    })
+    return async (dispatch) => {
+        dispatch(actionPending())
+        let payload;
+        try {
+            payload = await promise
+            dispatch(actionResolved(payload))
+        }
+        catch (e) {
+            dispatch(actionRejected(e))
+        }
+        return payload
+    }
+}
+
+export const store2 = createStore(combineReducers({
+    auth: authReducer,
+    promise: promiseReducer
+}), applyMiddleware(thunk));