ivar_n пре 3 година
родитељ
комит
9e13018743
3 измењених фајлова са 44 додато и 1 уклоњено
  1. 22 1
      src/App.js
  2. 13 0
      src/actions/routeAction.js
  3. 9 0
      src/reducers/routeReducer.js

+ 22 - 1
src/App.js

@@ -1,4 +1,4 @@
-import React, {useState, useEffect, useRef} from 'react';
+import React, {useState, useEffect, useRef, Component} from 'react';
 import logo from './logo.svg'
 import './App.scss'
 import {Provider, connect}   from 'react-redux'
@@ -28,6 +28,27 @@ const Page404 = () => (
   <h1>Тут ведутся работы</h1>
 )
 
+
+
+const RRoute = ({ action, component:Component, ...routeProps}) => {
+  const WrapperComponent = (componentProps) => {
+    action(componentProps.match)
+    return <Component {...componentProps} />
+  }
+  return <Route {...routeProps} component={WrapperComponent} />
+}
+const CRRoute = connect(null, {action: match => ({type: 'ROUTE', match})})(RRoute)
+
+// const ProtectedRoute = ({ fallback='/',
+//                           roles=["admin"],
+//                           auth,
+                          
+// })
+
+
+
+
+
 const AuthSwitch = ({token}) => {
   return (
     <>      

+ 13 - 0
src/actions/routeAction.js

@@ -0,0 +1,13 @@
+
+
+function* routeWorker({match}) {
+    console.log(match)
+    if (match.path in queries) {
+      const {name, query, variables} = queries[match.path](match)
+      yield call(promiseWorker, actionPromise(name, gql(query, variables)))
+    }
+  }
+  
+  function* routeWatcher() {
+    yield takeEvery('ROUTE', routeWorker)
+  }

+ 9 - 0
src/reducers/routeReducer.js

@@ -0,0 +1,9 @@
+
+
+
+export function routeReducer(state={}, {type, match}) {
+    if (type === 'ROUTE') {
+        return match
+    }
+    return state
+}