|
@@ -1,4 +1,6 @@
|
|
|
-import { url } from "../../App"
|
|
|
+import { store } from "."
|
|
|
+
|
|
|
+const url = 'http://hipstagram.node.ed.asmer.org.ua/graphql'
|
|
|
|
|
|
// функция getGql
|
|
|
function getGql(endpoint) {
|
|
@@ -31,7 +33,7 @@ function getGql(endpoint) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const gql = getGql('http://hipstagram.node.ed.asmer.org.ua/graphql')
|
|
|
+const gql = getGql(url)
|
|
|
|
|
|
// акшоны для promiseReducer
|
|
|
export const actionPending = nameOfPromise => ({ nameOfPromise, type: 'PROMISE', status: 'PENDING' })
|
|
@@ -64,7 +66,7 @@ export const actionFindPostOne = _id => actionPromise('PostFindOne', gql(`query
|
|
|
_id
|
|
|
}
|
|
|
likesCount owner {
|
|
|
- _id login nick avatar {
|
|
|
+ _id login nick avatar {
|
|
|
_id url
|
|
|
}
|
|
|
}
|
|
@@ -84,7 +86,7 @@ export const actionFindPostOne = _id => actionPromise('PostFindOne', gql(`query
|
|
|
|
|
|
|
|
|
// запрос на поиск конкретного юзера
|
|
|
-export const actionFindUserOne = _id => actionPromise('UserFindOne', gql(`query OneUserFind ($userOne: String) {
|
|
|
+export const actionFindUserOne = (_id, promiseName = 'UserFindOne') => actionPromise(promiseName, gql(`query OneUserFind ($userOne: String) {
|
|
|
UserFindOne(query: $userOne) {
|
|
|
_id createdAt login nick
|
|
|
avatar {
|
|
@@ -126,7 +128,7 @@ const actionAuthLogin = token => ({ type: 'AUTH_LOGIN', token })
|
|
|
const actionAuthLogout = () => ({ type: 'AUTH_LOGOUT' })
|
|
|
|
|
|
// Запрос на логин
|
|
|
-export const actionLogin = (login, password) => actionPromise('login', gql(`query Login($login: String!, $password: String!) {
|
|
|
+export const actionLogin = (login, password) => actionPromise('Login', gql(`query Login($login: String!, $password: String!) {
|
|
|
login(login: $login, password: $password)
|
|
|
}`, {
|
|
|
login,
|
|
@@ -152,13 +154,16 @@ export const actionFullLogin = (login, password) =>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// ========================
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-// Запрос на поиск ленты
|
|
|
-export const actionFeedFindOne = (arr, sortOne) => actionPromise('feed', gql(`query FeedFindOne ($feedOne: String){
|
|
|
+// Запрос на поиск ленты постов
|
|
|
+export const actionFeedFindOne = (arr, sortOne) => actionPromise('Feed', gql(`query FeedFindOne ($feedOne: String){
|
|
|
PostFind(query: $feedOne){
|
|
|
_id createdAt title text likesCount owner{
|
|
|
_id login avatar{
|
|
@@ -176,3 +181,97 @@ export const actionFeedFindOne = (arr, sortOne) => actionPromise('feed', gql(`qu
|
|
|
feedOne: JSON.stringify([{ ___owner: { $in: arr } }, { sort: [{ _id: sortOne }] }])
|
|
|
}))
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// =============================
|
|
|
+// Запрос для создания страницы юзера
|
|
|
+export const actionFullUserFindOne = _id =>
|
|
|
+ async dispatch => {
|
|
|
+ await dispatch(actionFindUserOne(_id))
|
|
|
+ dispatch(actionFeedFindOne([_id], -1))
|
|
|
+ }
|
|
|
+// ==============================
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// запрос для главной страницы ленты
|
|
|
+export const actionFeedFind = (id, sort) =>
|
|
|
+ async (dispatch, getState) => {
|
|
|
+ const userData = await dispatch(actionFindUserOne(id))
|
|
|
+ console.log('userData: ', userData)
|
|
|
+
|
|
|
+ // собираем список подписчиков
|
|
|
+ let followingList = []
|
|
|
+
|
|
|
+ for (const item of userData.following)
|
|
|
+ for (const [key, value] of Object.entries(item)) {
|
|
|
+ if (key === '_id') {
|
|
|
+ followingList.push(value)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log('followingList: ', followingList)
|
|
|
+
|
|
|
+ // console.log(666, store.getState().promise?.Feed?.status !== 'FULFILLED')
|
|
|
+
|
|
|
+ // if (store.getState().promise?.Feed?.status !== 'FULFILLED') {
|
|
|
+ dispatch(actionFeedFindOne(followingList, sort))
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// запрос на загрузку картинок на бек
|
|
|
+function fileUpload(file) {
|
|
|
+ const formData = new FormData()
|
|
|
+ formData.append('photo', file)
|
|
|
+
|
|
|
+
|
|
|
+ return (
|
|
|
+ fetch('http://hipstagram.node.ed.asmer.org.ua/upload', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ Authorization: 'Bearer ' + localStorage.authToken
|
|
|
+ },
|
|
|
+ body: formData
|
|
|
+ }).then(res => res.json())
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+function filesUpload(files) {
|
|
|
+ return Promise.all(files.map(fileUpload))
|
|
|
+}
|
|
|
+
|
|
|
+export const actionFilesUpload = (files) => actionPromise('FilesUpload',
|
|
|
+ filesUpload(files)
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// запрос на создание поста
|
|
|
+export const actionCreatePost = (params) => actionPromise('CreatePost', gql(
|
|
|
+ `mutation CreatePost($createNewPost: PostInput){
|
|
|
+ PostUpsert(post: $createNewPost){
|
|
|
+ _id
|
|
|
+ }
|
|
|
+}`, {
|
|
|
+ createNewPost: params
|
|
|
+}))
|
|
|
+
|
|
|
+// санк для создания поста и последующего перехода на его страницу
|
|
|
+export const actionFullCreatePost = (params) =>
|
|
|
+ async dispatch => {
|
|
|
+ const newPost = await dispatch(actionCreatePost(params))
|
|
|
+ console.log('Тут нужный резульата: ', newPost)
|
|
|
+
|
|
|
+ if (newPost) {
|
|
|
+ dispatch(actionFindPostOne(newPost._id))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|