|
@@ -2,20 +2,17 @@ import logo from './logo.svg';
|
|
|
import './App.css';
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
import { Router, Route, Link, Redirect, Switch, useParams } from 'react-router-dom';
|
|
|
-
|
|
|
import { createStore, combineRedusers, applyMiddleware } from 'redux';
|
|
|
import thunk from 'redux-thunk';
|
|
|
import { Provider, connect, useDispatch, useSelector } from 'react-redux';
|
|
|
-
|
|
|
import Feed from './components/feed';
|
|
|
-import Comments from './components/post';
|
|
|
import User from './components/user';
|
|
|
|
|
|
-// import { Provider } from 'react-redux';
|
|
|
+// импорт страниц
|
|
|
+import AsideMenu from './components/pages/structure/aside_menu';
|
|
|
|
|
|
import createHistory from "history/createBrowserHistory";
|
|
|
|
|
|
-
|
|
|
// ==============================================================================
|
|
|
// создание promiseReducer
|
|
|
function promiseReducer(state = {}, { type, status, payload, error, nameOfPromise }) {
|
|
@@ -48,7 +45,6 @@ const actionPromise = (nameOfPromise, promise) =>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// =============================================================
|
|
|
// функция getGql
|
|
|
function getGql(endpoint) {
|
|
@@ -83,7 +79,6 @@ function getGql(endpoint) {
|
|
|
|
|
|
const gql = getGql('http://hipstagram.node.ed.asmer.org.ua/graphql')
|
|
|
|
|
|
-
|
|
|
// запрос на все посты (для ленты общей)
|
|
|
const actionfindPosts = () => actionPromise('PostsFind', gql(`query AllPostsFind ($allPosts: String){
|
|
|
PostFind(query: $allPosts){
|
|
@@ -100,8 +95,6 @@ const actionfindPosts = () => actionPromise('PostsFind', gql(`query AllPostsFind
|
|
|
allPosts: JSON.stringify([{}])
|
|
|
}))
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// запрос на конкретный пост
|
|
|
const actionFindPostOne = _id => actionPromise('PostFindOne', gql(`query OnePostFind ($postOne: String){
|
|
|
PostFindOne (query: $postOne) {
|
|
@@ -131,8 +124,6 @@ const actionFindPostOne = _id => actionPromise('PostFindOne', gql(`query OnePost
|
|
|
postOne: JSON.stringify([{ _id }])
|
|
|
}))
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// запрос на конкретного юзера
|
|
|
const actionFindUserOne = _id => actionPromise('UserFindOne', gql(`query OneUserFind ($userOne: String) {
|
|
|
UserFindOne(query: $userOne) {
|
|
@@ -151,10 +142,6 @@ const actionFindUserOne = _id => actionPromise('UserFindOne', gql(`query OneUser
|
|
|
userOne: JSON.stringify([{ _id }])
|
|
|
}))
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
const store = createStore(promiseReducer, applyMiddleware(thunk))
|
|
|
store.subscribe(() => console.log(store.getState()))
|
|
|
|
|
@@ -163,8 +150,6 @@ store.dispatch(actionfindPosts())
|
|
|
// store.dispatch(actionFindUserOne())
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
const history = createHistory()
|
|
|
|
|
|
const Autorization = () =>
|
|
@@ -187,12 +172,6 @@ const CreatePost = () =>
|
|
|
Страницв создания поста
|
|
|
</div>
|
|
|
|
|
|
-// const User = () =>
|
|
|
-// // <div>
|
|
|
-// // Страница юзера
|
|
|
-// // </div>
|
|
|
-// <SimpleContainer />
|
|
|
-
|
|
|
const PageAbout = () =>
|
|
|
<div>
|
|
|
Страница "О нас"
|
|
@@ -210,11 +189,30 @@ const ReduxFeed = connect(state => ({ posts: state.PostsFind.payload }))(Feed)
|
|
|
// ==================================================
|
|
|
// страница одного поста
|
|
|
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)
|
|
|
+
|
|
|
// ====================================================
|
|
|
|
|
|
function App() {
|
|
@@ -222,21 +220,8 @@ function App() {
|
|
|
<Provider store={store}>
|
|
|
<Router history={history}>
|
|
|
<div className="wrapper" style={{ display: 'flex', minHeight: '100hv' }}>
|
|
|
- <aside style={{ width: '15%', minHeight: '100vh', backgroundColor: '#ffdbdb' }}>
|
|
|
- <Link to="/">Главная(она же Лента)</Link>
|
|
|
- <br />
|
|
|
- <Link to="/profile">Профиль</Link>
|
|
|
- <br />
|
|
|
- <Link to="/createpost">Создание поста</Link>
|
|
|
- <br />
|
|
|
- <Link to="/direct">Директ</Link>
|
|
|
- <br />
|
|
|
- <Link to="/about">О нас</Link>
|
|
|
- <br />
|
|
|
- <Link to="/registration">Регистрация</Link>
|
|
|
- <br />
|
|
|
- <Link to="/autorization">Авторизация</Link>
|
|
|
- </aside>
|
|
|
+
|
|
|
+ <AsideMenu />
|
|
|
<section style={{ width: '50%', margin: '0 auto', minHeight: '100hv', display: 'flex', flexDirection: 'column' }}>
|
|
|
<header style={{ backgroundColor: '#dbffe7' }}>
|
|
|
Тут будут какие-то заголовки или что-то вроде этого
|
|
@@ -247,7 +232,6 @@ function App() {
|
|
|
|
|
|
<Switch>
|
|
|
<Route path="/autorization" component={Autorization} />
|
|
|
- {/* <Route path="/profile" component={User} /> */}
|
|
|
<Route path="/user/:userId" component={CUser} />
|
|
|
|
|
|
<Route path="/registration" component={Registration} />
|