|
@@ -2,66 +2,79 @@
|
|
|
import './App.css';
|
|
|
import Layout from "./components/layout.js";
|
|
|
import {Provider, connect} from 'react-redux';
|
|
|
-import {Header, Footer, actionCatalogCard, Main} from "./components/index"
|
|
|
+import {Header, Footer, actionCatalogCard, Main, SearchInput} from "./components/index"
|
|
|
import {BrowserRouter as Router, Route, Link, Switch, Redirect} from 'react-router-dom';
|
|
|
import createHistory from "history/createBrowserHistory";
|
|
|
import Catalog from "./components/catalog"
|
|
|
import {createStore, combineReducers, applyMiddleware, compose} from 'redux';
|
|
|
import thunk from 'redux-thunk';
|
|
|
-import {gql, actionPromise} from "./reducers";
|
|
|
+import {gql, actionPromise, store, promiseReducer, actionSearch} from "./reducers";
|
|
|
+import { useState } from 'react';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-let toRegexp = (str) => {
|
|
|
- str = str.replace(/ +/g, " ").trim();
|
|
|
- str = "/" + str.split(" ").join("|") + "/";
|
|
|
- return str;
|
|
|
-};
|
|
|
|
|
|
-let toQuery = (str, fields = ["name", "description"]) => {
|
|
|
- str = toRegexp(str);
|
|
|
- let arr = fields.map((s) => {
|
|
|
- console.log(s, typeof s);
|
|
|
- return { [s]: str };
|
|
|
- });
|
|
|
- return { $or: arr };
|
|
|
-};
|
|
|
+// let toRegexp = (str) => {
|
|
|
+// str = str.replace(/ +/g, " ").trim();
|
|
|
+// str = "/" + str.split(" ").join("|") + "/";
|
|
|
+// return str;
|
|
|
+// };
|
|
|
+
|
|
|
+// let toQuery = (str, fields = ["name", "description"]) => {
|
|
|
+// str = toRegexp(str);
|
|
|
+// let arr = fields.map((s) => {
|
|
|
+// console.log(s, typeof s);
|
|
|
+// return { [s]: str };
|
|
|
+// });
|
|
|
+// return { $or: arr };
|
|
|
+// };
|
|
|
|
|
|
|
|
|
// toQuery(" klk lk nnnj klkm 555 ");
|
|
|
-function promiseReducer(state={}, action){
|
|
|
- if (action.type === 'PROMISE'){
|
|
|
- const { name="default", status, payload, error} = action
|
|
|
- if (status){
|
|
|
- return {
|
|
|
- ...state, [name]: {status, payload: (status === 'PENDING' && state[name] && state[name].payload) || payload, error}
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return state;
|
|
|
-}
|
|
|
+// function promiseReducer(state={}, action){
|
|
|
+// if (action.type === 'PROMISE'){
|
|
|
+// const { name="default", status, payload, error} = action
|
|
|
+// if (status){
|
|
|
+// return {
|
|
|
+// ...state, [name]: {status, payload: (status === 'PENDING' && state[name] && state[name].payload) || payload, error}
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return state;
|
|
|
+// }
|
|
|
|
|
|
|
|
|
-const store = createStore(combineReducers({
|
|
|
- promiseRed: promiseReducer
|
|
|
-}), compose(applyMiddleware(thunk)))
|
|
|
-
|
|
|
-function actionSearch(queryString) {
|
|
|
- return actionPromise('search', gql(`query goods($query: String) {
|
|
|
- GoodFind(query: $query) {
|
|
|
- name, price,
|
|
|
- images{url}, _id
|
|
|
- categories {
|
|
|
- _id
|
|
|
- createdAt
|
|
|
- name
|
|
|
- }
|
|
|
- }
|
|
|
- }`, {query: JSON.stringify([toQuery(queryString)])}))
|
|
|
-}
|
|
|
+// const store = createStore(combineReducers({
|
|
|
+// promiseRed: promiseReducer
|
|
|
+// }), compose(applyMiddleware(thunk)))
|
|
|
+
|
|
|
+// function actionSearch(queryString) {
|
|
|
+// return actionPromise('search', gql(`query goods($query: String) {
|
|
|
+// GoodFind(query: $query) {
|
|
|
+// name, price,
|
|
|
+// images{url}, _id
|
|
|
+// categories {
|
|
|
+// _id
|
|
|
+// createdAt
|
|
|
+// name
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }`, {query: JSON.stringify([toQuery(queryString)])}))
|
|
|
+// }
|
|
|
|
|
|
-store.dispatch(actionSearch("Apple"));
|
|
|
+// console.log(store.dispatch(actionSearch("Холодильник")));
|
|
|
+
|
|
|
+
|
|
|
+// const SearchInput = ({}) => {
|
|
|
+// const [name, changeValue] = useState("posuk");
|
|
|
+// return(
|
|
|
+// <>
|
|
|
+// <input type = "text" plaseholder = "Пошук" onChange = {(e) => changeValue(e.target.value)}/>
|
|
|
+// <button onClick = {() => console.log(store.dispatch(actionSearch(name)))}>пуск</button>
|
|
|
+// </>
|
|
|
+// )
|
|
|
+// }
|
|
|
|
|
|
function App() {
|
|
|
return (
|
|
@@ -70,7 +83,7 @@ function App() {
|
|
|
<Router history = {createHistory}>
|
|
|
|
|
|
<Header/>
|
|
|
-
|
|
|
+
|
|
|
<Main/>
|
|
|
|
|
|
<Footer/>
|