|
@@ -19,17 +19,6 @@ const backendURL = 'http://hipstagram.asmer.fs.a-level.com.ua';
|
|
const gql = getGQL(backendURL + '/graphql');
|
|
const gql = getGQL(backendURL + '/graphql');
|
|
|
|
|
|
|
|
|
|
-const uploadFile = file => {
|
|
|
|
- const fd = new FormData;
|
|
|
|
- fd.append('photo', file);
|
|
|
|
- return fetch(backendURL+'/upload', {
|
|
|
|
- method: "POST",
|
|
|
|
- headers: localStorage.authToken ? {Authorization: 'Bearer ' + localStorage.authToken} : {},
|
|
|
|
- body: fd
|
|
|
|
- }).then(res => res.json());
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -52,28 +41,32 @@ export const actionPromise = (name,promise) =>{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-export const actionUploadFile = file =>
|
|
|
|
- actionPromise('fileUpload', uploadFile(file));
|
|
|
|
-export const actionAvatar = (userrId, fileeId) =>
|
|
|
|
- actionPromise("userAvatar", gql(`mutation setAvatar($userId: String, $fileId: ID){
|
|
|
|
- UserUpsert(user:{_id: $userId, avatar: {_id: $fileId}}){
|
|
|
|
- _id, avatar{
|
|
|
|
- _id
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}`, {userId: userrId,
|
|
|
|
- fileId: fileeId}))
|
|
|
|
|
|
|
|
export const actionAuthLogin = (tokennn) =>({type:'AUTH_LOGIN',token:tokennn})
|
|
export const actionAuthLogin = (tokennn) =>({type:'AUTH_LOGIN',token:tokennn})
|
|
export const actionAuthLogout= () => ({type: 'AUTH_LOGOUT'})
|
|
export const actionAuthLogout= () => ({type: 'AUTH_LOGOUT'})
|
|
|
|
|
|
|
|
|
|
-export const actionFullRegister = (Login,password) =>
|
|
|
|
- actionPromise('fullRegister', gql(`mutation register($login:String!,$password:String!){
|
|
|
|
- UserUpsert(user:{login:$login,password:$password}){
|
|
|
|
- _id login
|
|
|
|
- }
|
|
|
|
- }`,{login: Login, password: password}))
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+export const actionFullRegister = (login,password) => async (dispatch, getState) => {
|
|
|
|
+ await dispatch(
|
|
|
|
+ actionPromise('fullRegister', gql(`mutation register($login:String!,$password:String!){
|
|
|
|
+ UserUpsert(user:{login:$login,password:$password}){
|
|
|
|
+ _id login
|
|
|
|
+ }
|
|
|
|
+ }`,{login: login, password: password}))
|
|
|
|
+ );
|
|
|
|
+ const {
|
|
|
|
+ promise: {fullRegister}
|
|
|
|
+ } = getState();
|
|
|
|
+ if (fullRegister.status === "fULFILLED") {
|
|
|
|
+ dispatch(actionFullLogin(login,password))
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
export const actionFullLogin = (login,password) => async (dispatch) => {
|
|
export const actionFullLogin = (login,password) => async (dispatch) => {
|
|
const tokennn = await dispatch(
|
|
const tokennn = await dispatch(
|
|
@@ -84,6 +77,32 @@ export const actionFullLogin = (login,password) => async (dispatch) => {
|
|
await dispatch(actionAuthLogin(tokennn));
|
|
await dispatch(actionAuthLogin(tokennn));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+export const uploadFile = file => {
|
|
|
|
+ const fd = new FormData();
|
|
|
|
+ fd.append('photo', file);
|
|
|
|
+return fetch(backendURL+'/upload', {
|
|
|
|
+ method: "POST",
|
|
|
|
+ headers: localStorage.authToken ? {Authorization: 'Bearer ' + localStorage.authToken} : {},
|
|
|
|
+ body: fd
|
|
|
|
+}).then(res => res.json());
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+export const actionUploadFile = file =>
|
|
|
|
+ actionPromise('fileUpload', uploadFile(file));
|
|
|
|
+export const actionAvatar = (userrId, fileeId) =>
|
|
|
|
+ actionPromise("userAvatar", gql(`mutation setAvatar($userId: String, $fileId: ID){
|
|
|
|
+ UserUpsert(user:{_id: $userId, avatar: {_id: $fileId}}){
|
|
|
|
+ _id, avatar{
|
|
|
|
+ _id
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}`, {userId: userrId,
|
|
|
|
+ fileId: fileeId}))
|
|
|
|
+
|
|
export const actionAboutMe = (_id) =>
|
|
export const actionAboutMe = (_id) =>
|
|
actionPromise("userInfo", gql(`query AboutMe ($Id: String){
|
|
actionPromise("userInfo", gql(`query AboutMe ($Id: String){
|
|
UserFindOne(query:$Id){
|
|
UserFindOne(query:$Id){
|