|
@@ -2,20 +2,14 @@ import logo from './logo.svg';
|
|
import './App.css';
|
|
import './App.css';
|
|
import React, { useState, useEffect } from 'react';
|
|
import React, { useState, useEffect } from 'react';
|
|
import { Router, Route, Link, Redirect, Switch, useParams } from 'react-router-dom';
|
|
import { Router, Route, Link, Redirect, Switch, useParams } from 'react-router-dom';
|
|
-
|
|
|
|
import { createStore, combineRedusers, applyMiddleware } from 'redux';
|
|
import { createStore, combineRedusers, applyMiddleware } from 'redux';
|
|
import thunk from 'redux-thunk';
|
|
import thunk from 'redux-thunk';
|
|
import { Provider, connect, useDispatch, useSelector } from 'react-redux';
|
|
import { Provider, connect, useDispatch, useSelector } from 'react-redux';
|
|
-
|
|
|
|
import Feed from './components/feed';
|
|
import Feed from './components/feed';
|
|
-import Comments from './components/post';
|
|
|
|
import User from './components/user';
|
|
import User from './components/user';
|
|
|
|
|
|
-// import { Provider } from 'react-redux';
|
|
|
|
-
|
|
|
|
import createHistory from "history/createBrowserHistory";
|
|
import createHistory from "history/createBrowserHistory";
|
|
|
|
|
|
-
|
|
|
|
// ==============================================================================
|
|
// ==============================================================================
|
|
// создание promiseReducer
|
|
// создание promiseReducer
|
|
function promiseReducer(state = {}, { type, status, payload, error, nameOfPromise }) {
|
|
function promiseReducer(state = {}, { type, status, payload, error, nameOfPromise }) {
|
|
@@ -48,7 +42,6 @@ const actionPromise = (nameOfPromise, promise) =>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// =============================================================
|
|
// =============================================================
|
|
// функция getGql
|
|
// функция getGql
|
|
function getGql(endpoint) {
|
|
function getGql(endpoint) {
|
|
@@ -83,7 +76,6 @@ function getGql(endpoint) {
|
|
|
|
|
|
const gql = getGql('http://hipstagram.node.ed.asmer.org.ua/graphql')
|
|
const gql = getGql('http://hipstagram.node.ed.asmer.org.ua/graphql')
|
|
|
|
|
|
-
|
|
|
|
// запрос на все посты (для ленты общей)
|
|
// запрос на все посты (для ленты общей)
|
|
const actionfindPosts = () => actionPromise('PostsFind', gql(`query AllPostsFind ($allPosts: String){
|
|
const actionfindPosts = () => actionPromise('PostsFind', gql(`query AllPostsFind ($allPosts: String){
|
|
PostFind(query: $allPosts){
|
|
PostFind(query: $allPosts){
|
|
@@ -100,8 +92,6 @@ const actionfindPosts = () => actionPromise('PostsFind', gql(`query AllPostsFind
|
|
allPosts: JSON.stringify([{}])
|
|
allPosts: JSON.stringify([{}])
|
|
}))
|
|
}))
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
// запрос на конкретный пост
|
|
// запрос на конкретный пост
|
|
const actionFindPostOne = _id => actionPromise('PostFindOne', gql(`query OnePostFind ($postOne: String){
|
|
const actionFindPostOne = _id => actionPromise('PostFindOne', gql(`query OnePostFind ($postOne: String){
|
|
PostFindOne (query: $postOne) {
|
|
PostFindOne (query: $postOne) {
|
|
@@ -131,12 +121,10 @@ const actionFindPostOne = _id => actionPromise('PostFindOne', gql(`query OnePost
|
|
postOne: JSON.stringify([{ _id }])
|
|
postOne: JSON.stringify([{ _id }])
|
|
}))
|
|
}))
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
// запрос на конкретного юзера
|
|
// запрос на конкретного юзера
|
|
const actionFindUserOne = _id => actionPromise('UserFindOne', gql(`query OneUserFind ($userOne: String) {
|
|
const actionFindUserOne = _id => actionPromise('UserFindOne', gql(`query OneUserFind ($userOne: String) {
|
|
UserFindOne(query: $userOne) {
|
|
UserFindOne(query: $userOne) {
|
|
- createdAt login nick
|
|
|
|
|
|
+ _id createdAt login nick
|
|
avatar {
|
|
avatar {
|
|
_id url
|
|
_id url
|
|
}
|
|
}
|
|
@@ -151,18 +139,12 @@ const actionFindUserOne = _id => actionPromise('UserFindOne', gql(`query OneUser
|
|
userOne: JSON.stringify([{ _id }])
|
|
userOne: JSON.stringify([{ _id }])
|
|
}))
|
|
}))
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
const store = createStore(promiseReducer, applyMiddleware(thunk))
|
|
const store = createStore(promiseReducer, applyMiddleware(thunk))
|
|
store.subscribe(() => console.log(store.getState()))
|
|
store.subscribe(() => console.log(store.getState()))
|
|
|
|
|
|
store.dispatch(actionfindPosts())
|
|
store.dispatch(actionfindPosts())
|
|
// store.dispatch(actionCategoryFind())
|
|
// store.dispatch(actionCategoryFind())
|
|
-store.dispatch(actionFindUserOne())
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+// store.dispatch(actionFindUserOne())
|
|
|
|
|
|
|
|
|
|
const history = createHistory()
|
|
const history = createHistory()
|
|
@@ -187,12 +169,6 @@ const CreatePost = () =>
|
|
Страницв создания поста
|
|
Страницв создания поста
|
|
</div>
|
|
</div>
|
|
|
|
|
|
-// const User = () =>
|
|
|
|
-// // <div>
|
|
|
|
-// // Страница юзера
|
|
|
|
-// // </div>
|
|
|
|
-// <SimpleContainer />
|
|
|
|
-
|
|
|
|
const PageAbout = () =>
|
|
const PageAbout = () =>
|
|
<div>
|
|
<div>
|
|
Страница "О нас"
|
|
Страница "О нас"
|
|
@@ -210,11 +186,30 @@ const ReduxFeed = connect(state => ({ posts: state.PostsFind.payload }))(Feed)
|
|
// ==================================================
|
|
// ==================================================
|
|
// страница одного поста
|
|
// страница одного поста
|
|
const CComments = connect(state => ({ post: state?.PostFindOne?.payload }), { loadPost: actionFindPostOne })(Comments)
|
|
const CComments = connect(state => ({ post: state?.PostFindOne?.payload }), { loadPost: actionFindPostOne })(Comments)
|
|
-// ====================================================
|
|
|
|
|
|
+
|
|
|
|
+function Comments({ post = {}, loadPost }) {
|
|
|
|
+
|
|
|
|
+ const { postId } = useParams() // отслеживаем изменения в урле
|
|
|
|
+ // const post2 = useSelector(state => state?.CategoryGoodsAndSubCategoryGoods?.payload)
|
|
|
|
+ console.log(66, postId)
|
|
|
|
+
|
|
|
|
+ useEffect(() => { loadPost(postId) }, [postId]) // перезапускаем loadPost, если произошло изменение в урле
|
|
|
|
+
|
|
|
|
+ // console.log(post)
|
|
|
|
+
|
|
|
|
+ return (
|
|
|
|
+ <div>
|
|
|
|
+ {/* <div>{user} and {postId}</div> */}
|
|
|
|
+ тут будут отображаться все комментарии под постом
|
|
|
|
+ <h2>{post.createdAt}</h2>
|
|
|
|
+ </div>
|
|
|
|
+ )
|
|
|
|
+}
|
|
|
|
|
|
// ==================================================
|
|
// ==================================================
|
|
// страница юзера
|
|
// страница юзера
|
|
const CUser = connect(state => ({ user: state?.UserFindOne?.payload }), { loadUser: actionFindUserOne })(User)
|
|
const CUser = connect(state => ({ user: state?.UserFindOne?.payload }), { loadUser: actionFindUserOne })(User)
|
|
|
|
+
|
|
// ====================================================
|
|
// ====================================================
|
|
|
|
|
|
function App() {
|
|
function App() {
|
|
@@ -248,14 +243,14 @@ function App() {
|
|
<Switch>
|
|
<Switch>
|
|
<Route path="/autorization" component={Autorization} />
|
|
<Route path="/autorization" component={Autorization} />
|
|
{/* <Route path="/profile" component={User} /> */}
|
|
{/* <Route path="/profile" component={User} /> */}
|
|
- <Route path="/profile" component={CUser} />
|
|
|
|
|
|
+ <Route path="/user/:userId" component={CUser} />
|
|
|
|
|
|
<Route path="/registration" component={Registration} />
|
|
<Route path="/registration" component={Registration} />
|
|
<Route path="/" component={ReduxFeed} exact />
|
|
<Route path="/" component={ReduxFeed} exact />
|
|
<Route path="/createpost" component={CreatePost} />
|
|
<Route path="/createpost" component={CreatePost} />
|
|
<Route path="/direct" component={Direct} />
|
|
<Route path="/direct" component={Direct} />
|
|
<Route path="/about" component={PageAbout} />
|
|
<Route path="/about" component={PageAbout} />
|
|
- <Route path="/:postId" component={CComments} />
|
|
|
|
|
|
+ <Route path="/post/:postId" component={CComments} />
|
|
|
|
|
|
|
|
|
|
<Route path="*" component={Page404} />
|
|
<Route path="*" component={Page404} />
|