|
@@ -2,6 +2,7 @@
|
|
|
import {Provider, connect} from 'react-redux';
|
|
|
import {createStore, combineReducers, applyMiddleware} from 'redux';
|
|
|
import thunk from 'redux-thunk';
|
|
|
+import {actionPromise} from "./index"
|
|
|
|
|
|
|
|
|
///reducer, где набор экшн.типов + функции.(если - то)
|
|
@@ -15,40 +16,12 @@ import thunk from 'redux-thunk';
|
|
|
//параметры - то, что получаем(?). Засунуть внутрь функции(єкшн) в которой диспатч.
|
|
|
|
|
|
|
|
|
-const getGQL = url =>
|
|
|
- (query, variables={}) =>
|
|
|
- fetch(url,
|
|
|
- {method: 'POST',
|
|
|
- headers: {
|
|
|
- 'Accept': 'application/json',
|
|
|
- 'Content-Type': 'application/json',
|
|
|
- ...(localStorage.authToken ? {Authorization: `Bearer ${localStorage.authToken}`} : {})
|
|
|
- },
|
|
|
- body: JSON.stringify({query,variables})})
|
|
|
- .then(res => res.json())
|
|
|
-
|
|
|
-export 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;
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
-const gql = getGQL("http://shop-roles.asmer.fs.a-level.com.ua/graphql");
|
|
|
+import {gql} from "./index"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
const actionCatalogCard = () => {
|
|
|
return async dispatch => {
|