|
@@ -34,8 +34,6 @@ function promiseReducer(state={}, {type, status, payload, error, name}){
|
|
|
}
|
|
|
|
|
|
|
|
|
-//под товаром сделать кнопку "купить"
|
|
|
-
|
|
|
const store = createStore(promiseReducer)
|
|
|
const unsubscribe1 = store.subscribe(() => console.log(store.getState()))
|
|
|
|
|
@@ -69,14 +67,14 @@ const actionPromise = (name, promise) =>
|
|
|
},
|
|
|
body: JSON.stringify({query, variables})
|
|
|
}).then(resp => resp.json())
|
|
|
- // .then(data => {
|
|
|
- // if ("errors" in data) {
|
|
|
- // throw new Error('ашипка, угадывай што не так')
|
|
|
- // }
|
|
|
- // else {
|
|
|
- // return data.data[Object.keys(variables)[0]]
|
|
|
- // }
|
|
|
- // })
|
|
|
+ .then(data => {
|
|
|
+ if ("errors" in data) {
|
|
|
+ throw new Error('ашипка, угадывай што не так')
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return data.data[Object.keys(variables)[0]]
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -94,7 +92,7 @@ const goodById = goodId => {
|
|
|
_id name
|
|
|
}
|
|
|
}
|
|
|
- }`, { id })
|
|
|
+ }`, {GoodFindOne: '', id })
|
|
|
}
|
|
|
|
|
|
const actionGoodById = id =>
|
|
@@ -107,7 +105,7 @@ const actionRootCategories = () =>
|
|
|
_id name
|
|
|
}
|
|
|
}
|
|
|
- `, {query: JSON.stringify([{parent:null}])}))
|
|
|
+ `, {CategoryFind:'', query: JSON.stringify([{parent:null}])}))
|
|
|
|
|
|
const actionCategoryById = (_id) =>
|
|
|
actionPromise('catById', shopGQL(`query catById($query:String){
|
|
@@ -118,7 +116,7 @@ const actionCategoryById = (_id) =>
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }`, {query: JSON.stringify([{_id}])}))
|
|
|
+ }`, {CategoryFindOne:'', query: JSON.stringify([{_id}])}))
|
|
|
|
|
|
|
|
|
store.dispatch(actionRootCategories())
|
|
@@ -138,7 +136,7 @@ function drawMainMenu(){
|
|
|
let cats = store.getState().rootCategories.payload
|
|
|
if (cats){ //каждый раз дорисовываются в body
|
|
|
aside.innerText = ''
|
|
|
- for (let {_id, name} of cats.data.CategoryFind){
|
|
|
+ for (let {_id, name} of cats){
|
|
|
let catA = document.createElement('a')
|
|
|
catA.href = `#/categories/${_id}`
|
|
|
catA.innerText = name
|
|
@@ -158,11 +156,11 @@ store.subscribe(() => {
|
|
|
if (catById){
|
|
|
main.innerText = ''
|
|
|
let categoryName = document.createElement('div')
|
|
|
- categoryName.innerText = catById.data.CategoryFindOne.name
|
|
|
+ categoryName.innerText = catById.name
|
|
|
categoryName.style.fontSize = '25px'
|
|
|
categoryName.style.fontWeight = 'bold'
|
|
|
main.append(categoryName)
|
|
|
- for (let {_id, name} of catById.data.CategoryFindOne.goods){
|
|
|
+ for (let {_id, name} of catById.goods){
|
|
|
let good = document.createElement('a')
|
|
|
good.href = `#/good/${_id}`
|
|
|
good.innerText = name
|
|
@@ -178,7 +176,7 @@ store.subscribe(() => {
|
|
|
const goodById = store.getState().goodById?.payload
|
|
|
if (goodById){
|
|
|
main.innerText = ''
|
|
|
- let {name, description, price} = goodById.data.GoodFindOne
|
|
|
+ let {name, description, price} = goodById
|
|
|
let goodName = document.createElement('div')
|
|
|
goodName.innerText = name
|
|
|
goodName.style.fontSize = '35px'
|