|
@@ -2,17 +2,15 @@ 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 RecipeReviewCard from './components/Feed' // импортируем карточку поста в лентеы
|
|
|
-import Box from '@mui/material/Box';
|
|
|
-import Stack from '@mui/material/Stack';
|
|
|
-import Paper from '@mui/material/Paper';
|
|
|
-import { styled } from '@mui/material/styles';
|
|
|
-
|
|
|
|
|
|
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 createHistory from "history/createBrowserHistory";
|
|
@@ -87,33 +85,84 @@ const gql = getGql('http://hipstagram.node.ed.asmer.org.ua/graphql')
|
|
|
|
|
|
|
|
|
// запрос на все посты (для ленты общей)
|
|
|
-const actionfindPosts = () => actionPromise('PostsFind', gql(`query findPosts($allPosts: String){
|
|
|
- PostFind(query: $allPosts){
|
|
|
- _id createdAt title text likesCount images {url} owner{_id login nick} comments{
|
|
|
- _id
|
|
|
+const actionfindPosts = () => actionPromise('PostsFind', gql(`query AllPostsFind ($allPosts: String){
|
|
|
+ PostFind(query: $allPosts){
|
|
|
+ _id createdAt title text likesCount
|
|
|
+ images {
|
|
|
+ url
|
|
|
+ }
|
|
|
+ owner {
|
|
|
+ _id login nick
|
|
|
}
|
|
|
- }}`, {
|
|
|
+
|
|
|
+ }
|
|
|
+}`, {
|
|
|
allPosts: JSON.stringify([{}])
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
// запрос на конкретный пост
|
|
|
-const actionFindPostOne = _id => actionPromise('PostFindOne', gql(`
|
|
|
-query PostFindOne ($postOne: String){
|
|
|
+const actionFindPostOne = _id => actionPromise('PostFindOne', gql(`query OnePostFind ($postOne: String){
|
|
|
PostFindOne (query: $postOne) {
|
|
|
- _id createdAt title text likesCount images {url} owner{_id login nick}
|
|
|
+ _id createdAt title text likesCount
|
|
|
+ images {
|
|
|
+ url
|
|
|
+ }
|
|
|
+ comments {
|
|
|
+ _id createdAt text answers {
|
|
|
+ _id createdAt text likes {
|
|
|
+ _id
|
|
|
+ }
|
|
|
+ likesCount owner {
|
|
|
+ _id login nick avatar {
|
|
|
+ _id url
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ likesCount
|
|
|
+ }
|
|
|
+ owner {
|
|
|
+ _id login nick
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}`, {
|
|
|
postOne: JSON.stringify([{ _id }])
|
|
|
}))
|
|
|
|
|
|
|
|
|
+
|
|
|
+// запрос на конкретного юзера
|
|
|
+const actionFindUserOne = _id => actionPromise('UserFindOne', gql(`query OneUserFind ($userOne: String) {
|
|
|
+ UserFindOne(query: $userOne) {
|
|
|
+ _id createdAt login nick
|
|
|
+ avatar {
|
|
|
+ _id url
|
|
|
+ }
|
|
|
+ followers {
|
|
|
+ _id login nick avatar {_id url}
|
|
|
+ }
|
|
|
+ following {
|
|
|
+ _id login nick avatar {_id url}
|
|
|
+ }
|
|
|
+ }
|
|
|
+}`, {
|
|
|
+ userOne: JSON.stringify([{ _id }])
|
|
|
+}))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
const store = createStore(promiseReducer, applyMiddleware(thunk))
|
|
|
store.subscribe(() => console.log(store.getState()))
|
|
|
|
|
|
store.dispatch(actionfindPosts())
|
|
|
// store.dispatch(actionCategoryFind())
|
|
|
+// store.dispatch(actionFindUserOne())
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
const history = createHistory()
|
|
@@ -133,42 +182,16 @@ const Direct = () =>
|
|
|
Direct
|
|
|
</div>
|
|
|
|
|
|
-// ===================================================
|
|
|
-// сам item для поста
|
|
|
-const Item = styled(Paper)(({ theme }) => ({
|
|
|
- backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
|
|
|
- width: 500
|
|
|
-}));
|
|
|
-
|
|
|
-// const Feed = ({ posts = arrPosts }) => {
|
|
|
-const Feed = ({ posts = [] }) => {
|
|
|
- return (
|
|
|
- <Box sx={{
|
|
|
- width: '500',
|
|
|
- height: '600',
|
|
|
- margin: '10, 20'
|
|
|
- }}>
|
|
|
- {/* spacing - это отступ между карточками в ленте */}
|
|
|
- <Stack spacing={1}>
|
|
|
- {/* {posts.map(post => <Item key={post._id}><RecipeReviewCard date={post.createdAt} title={post.title} text={post.text} likesCount={post.likesCount} nickName={post.owner.nick} login={post.owner.login} /></Item>)} */}
|
|
|
- {posts.map(post => <Item key={post._id}><RecipeReviewCard postData={post} /></Item>)}
|
|
|
- </Stack>
|
|
|
- </Box >
|
|
|
- );
|
|
|
-}
|
|
|
-
|
|
|
-const ReduxFeed = connect(state => ({ posts: state.PostsFind.payload }))(Feed)
|
|
|
-
|
|
|
-// ================================================
|
|
|
const CreatePost = () =>
|
|
|
<div>
|
|
|
Страницв создания поста
|
|
|
</div>
|
|
|
|
|
|
-const User = () =>
|
|
|
- <div>
|
|
|
- Страница юзера
|
|
|
- </div>
|
|
|
+// const User = () =>
|
|
|
+// // <div>
|
|
|
+// // Страница юзера
|
|
|
+// // </div>
|
|
|
+// <SimpleContainer />
|
|
|
|
|
|
const PageAbout = () =>
|
|
|
<div>
|
|
@@ -181,31 +204,19 @@ const Page404 = () =>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
+// создаем компонент ленты на основе стандартного, который отслеживает все изменения state
|
|
|
+const ReduxFeed = connect(state => ({ posts: state.PostsFind.payload }))(Feed)
|
|
|
+
|
|
|
// ==================================================
|
|
|
// страница одного поста
|
|
|
-
|
|
|
-const Comments = ({ post = {}, loadPost }) => {
|
|
|
-
|
|
|
-
|
|
|
- const { postId } = useParams()
|
|
|
- // const post2 = useSelector(state => state?.CategoryGoodsAndSubCategoryGoods?.payload)
|
|
|
-
|
|
|
- useEffect(() => { loadPost(postId) }, [postId])
|
|
|
-
|
|
|
- return (
|
|
|
- <div>
|
|
|
- {/* <div>{user} and {postId}</div> */}
|
|
|
- тут будут отображаться все комментарии под постом
|
|
|
- <h2>{post.createdAt}</h2>
|
|
|
- </div>
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
-// store.dispatch(actionFindPostOne())
|
|
|
-
|
|
|
const CComments = connect(state => ({ post: state?.PostFindOne?.payload }), { loadPost: actionFindPostOne })(Comments)
|
|
|
// ====================================================
|
|
|
|
|
|
+// ==================================================
|
|
|
+// страница юзера
|
|
|
+const CUser = connect(state => ({ user: state?.UserFindOne?.payload }), { loadUser: actionFindUserOne })(User)
|
|
|
+// ====================================================
|
|
|
+
|
|
|
function App() {
|
|
|
return (
|
|
|
<Provider store={store}>
|
|
@@ -236,13 +247,15 @@ function App() {
|
|
|
|
|
|
<Switch>
|
|
|
<Route path="/autorization" component={Autorization} />
|
|
|
- <Route path="/profile" component={User} />
|
|
|
+ {/* <Route path="/profile" component={User} /> */}
|
|
|
+ <Route path="/user/:userId" component={CUser} />
|
|
|
+
|
|
|
<Route path="/registration" component={Registration} />
|
|
|
<Route path="/" component={ReduxFeed} exact />
|
|
|
<Route path="/createpost" component={CreatePost} />
|
|
|
<Route path="/direct" component={Direct} />
|
|
|
<Route path="/about" component={PageAbout} />
|
|
|
- <Route path="/:postId" component={CComments} />
|
|
|
+ <Route path="/post/:postId" component={CComments} />
|
|
|
|
|
|
|
|
|
<Route path="*" component={Page404} />
|