|
@@ -8,80 +8,47 @@ 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, store, promiseReducer, actionSearch} from "./reducers";
|
|
|
-import { useState } from 'react';
|
|
|
+import {gql, actionPromise, store, promiseReducer, actionSearch, urlUpload} from "./reducers";
|
|
|
+import { useState, useRef } 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 };
|
|
|
-// };
|
|
|
+const UpdateForm = ({}) => {
|
|
|
+ const formRef = useRef(null);
|
|
|
+ const [isUpdate, changeIt] = useState(false)
|
|
|
+ const updateAction = async () => {
|
|
|
+ fetch(`${urlUpload}/upload`, {
|
|
|
+ method: "POST",
|
|
|
+ headers: localStorage.authToken ? {Authorization: 'Bearer ' + localStorage.authToken} : {},
|
|
|
+ body: new FormData(formRef.current)
|
|
|
+ })
|
|
|
+ .then((res) => res.json()).then(res => console.log(res))
|
|
|
|
|
|
+ changeIt(true)
|
|
|
+ }
|
|
|
|
|
|
-// 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;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-// 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)])}))
|
|
|
-// }
|
|
|
-
|
|
|
-// console.log(store.dispatch(actionSearch("Холодильник")));
|
|
|
+ return(
|
|
|
+ <>
|
|
|
+ <form action="/upload" method="post" enctype="multipart/form-data" id='form' ref={formRef} onChange = {updateAction}>
|
|
|
+ <input type="file" name="photo" id='photo'/>
|
|
|
+ </form>
|
|
|
|
|
|
+ <img src = {`${urlUpload}/images/cbd7145dbc78ced471951c70f571f871`}/>
|
|
|
+ </>
|
|
|
+ )
|
|
|
+}
|
|
|
|
|
|
-// 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 (
|
|
|
<>
|
|
|
<Provider store={store}>
|
|
|
<Router history = {createHistory}>
|
|
|
-
|
|
|
+ {/* <UpdateForm/> */}
|
|
|
<Header/>
|
|
|
|
|
|
<Main/>
|