Browse Source

cw localStorageReduscer

ivar_n 3 years ago
parent
commit
d111413934

+ 5 - 3
src/actions/index.js

@@ -5,7 +5,6 @@ export {
    actionAboutMe,
    actionAboutMe,
    actionSetAvatar,
    actionSetAvatar,
 } from './authActions'
 } from './authActions'
-
 export {
 export {
    actionAddChat, 
    actionAddChat, 
    actionUpdateChat,
    actionUpdateChat,
@@ -25,9 +24,12 @@ export {
    actionUploadFile,
    actionUploadFile,
 } from './mediaActions'
 } from './mediaActions'
 
 
-export {
+// export {
+//    actionFindUsers
+// } from './findActions'
+
+
 
 
-} from './findActions'
 
 
 
 
 
 

+ 8 - 8
src/helpers/printStrReq.js

@@ -1,11 +1,11 @@
 
 
 export const printStrReq = (str, amount) => {
 export const printStrReq = (str, amount) => {
-   if (!str) {
-      return
-   } else {
-      return (str.length >= amount) ? "" : 
-      ` минимум ${amount} символ${(((amount[amount.length - 1] == 1) && (amount[amount.length - 2] != 1)) ? '' :
-         ((amount[amount.length - 1] > 1) && (amount[amount.length - 1] < 5) && (amount[amount.length - 2] != 1)) ? 'а' :
-            'ов')}`
-   }   
+   if (str === undefined) {
+      return 
+   } 
+   return (str.length >= amount) ? "" : 
+   ` минимум ${amount} символ${(((amount[amount.length - 1] == 1) && (amount[amount.length - 2] != 1)) ? '' :
+      ((amount[amount.length - 1] > 1) && (amount[amount.length - 1] < 5) && (amount[amount.length - 2] != 1)) ? 'а' :
+         'ов')}`
+   
 }
 }

+ 14 - 4
src/reducers/index.js

@@ -1,11 +1,15 @@
 // работа со стейтом, подключение редьюсеров, близкие к редьюсерам экшны
 // работа со стейтом, подключение редьюсеров, близкие к редьюсерам экшны
-export {store} from './store'
-export {actionPromise} from './promiseReducer'
 export {
 export {
+    promiseReducer,
+    actionPromise
+} from './promiseReducer'
+export {
+    authReducer,
     actionAuthLogin, 
     actionAuthLogin, 
     actionAuthLogout
     actionAuthLogout
 } from './authReducer'
 } from './authReducer'
 export {
 export {
+    chatsReducer,
     actionAddListInChats,
     actionAddListInChats,
     actionAddChatInChats, 
     actionAddChatInChats, 
     actionUpdateChatInChats, 
     actionUpdateChatInChats, 
@@ -15,12 +19,18 @@ export {
     actionUpdateMsgInChat,
     actionUpdateMsgInChat,
 } from './chatsReducer'
 } from './chatsReducer'
 
 
+export {localStoredReducer} from './localStoredReducer'
+
+export {store} from './store'
+
 
 
 
 
 // const socket = io("ws://chat.fs.a-level.com.ua")
 // const socket = io("ws://chat.fs.a-level.com.ua")
-// socket.on('msg', msg => {    
+
+// socket.emit('msg', {}) только при отправке токена 
+// socket.on('msg', msg => { 
+//  диспатч месседжей в чат редьюсер   
 // })
 // })
-// socket.emit('msg', {})
 
 
 
 
 
 

+ 14 - 0
src/reducers/localStoredReducer.js

@@ -0,0 +1,14 @@
+
+
+
+export const localStoredReducer = (reducer, localStorageName) => (
+    (state, action) => {
+        if (!state && localStorage[localStorageName]) {
+            return JSON.parse(localStorage[localStorageName])
+        } else {
+            let newState = reducer(state, action)
+            localStorage.setItem(localStorageName, JSON.stringify(newState))
+            return newState
+        }
+    }
+)

+ 20 - 11
src/reducers/store.js

@@ -1,19 +1,28 @@
 import {createStore, combineReducers, applyMiddleware} from 'redux'
 import {createStore, combineReducers, applyMiddleware} from 'redux'
 import thunk from 'redux-thunk'
 import thunk from 'redux-thunk'
-import {promiseReducer} from './promiseReducer'
-import {authReducer} from './authReducer'
-import {chatsReducer} from './chatsReducer'
+import {promiseReducer} from '../reducers'
+import {authReducer} from '../reducers'
+import {chatsReducer} from '../reducers'
+import {localStoredReducer} from '../reducers'
+
 import {actionAboutMe} from '../actions'
 import {actionAboutMe} from '../actions'
+import * as shoto from '../actions'
+
+console.log(shoto)
+// console.log(Object.entries(shoto))
+// debugger;
 
 
+export const store =  createStore (  combineReducers({ 
+                                          promise: promiseReducer, 
+                                          auth: authReducer, 
+                                          chats: chatsReducer
+                                                }),
+                                    applyMiddleware(thunk)
+                        )
+console.log(store)
 
 
-export const store =  createStore (   combineReducers({ 
-                  promise: promiseReducer, 
-                  auth: authReducer, 
-                  chats: chatsReducer
-                        }),
-               applyMiddleware(thunk)
-               )
-// actionAboutMe()
+setTimeout(() => store.dispatch(actionAboutMe()), 0)
+// store.dispatch(actionAboutMe())
 
 
 store.subscribe(() => console.log(store.getState()))
 store.subscribe(() => console.log(store.getState()))