|
@@ -41,40 +41,68 @@ let reg = async(login, password) => {
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
-let ChangePass = async(login, password, newPassword) => {
|
|
|
- let query = `mutation changePass($login:String!, $password:String!, $newPassword:String!) {
|
|
|
- changePassword(
|
|
|
- login: $login,
|
|
|
- password: $password,
|
|
|
- newPassword: $newPassword
|
|
|
-
|
|
|
- ){
|
|
|
- _id
|
|
|
- }`
|
|
|
+export const actionAuthLogout = () => ({type: 'LOGOUT'})
|
|
|
+const actionAuthLogin = token => ({type: 'LOGIN', token})
|
|
|
+const actionLogin = (login, password) => actionPromise("login", log(login, password))
|
|
|
+const actionReg = (login, password) => actionPromise("reg", reg(login, password))
|
|
|
|
|
|
- let variables = {"login":login, "password":password, newPassword:"newPassword"}
|
|
|
+export const actionFullLogin = (login, password) => async(dispatch) => {
|
|
|
+let result = await dispatch(actionLogin(login, password))
|
|
|
+ if (result !== null){
|
|
|
+ dispatch(actionAuthLogin(result))
|
|
|
+ } else {
|
|
|
+ alert ('That user doesn’t exist!')
|
|
|
+ localStorage.clear()
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- let res = await gql(query, variables)
|
|
|
- return res
|
|
|
+export const actionFullRegister = (login, password) => async(dispatch) => {
|
|
|
+ let result = await dispatch(actionReg(login, password))
|
|
|
+ if(result?.data?.createUser !== null) {
|
|
|
+ dispatch(actionFullLogin(login, password))
|
|
|
+ } else {
|
|
|
+ alert('Such a user already exists!')
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-let SnippetUpsert = async (title, description, files , id) => {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+let SnippetUpsert = async (title, description, files) => {
|
|
|
let query = `mutation SnippetUpsert($snippet:SnippetInput) {
|
|
|
SnippetUpsert(snippet:$snippet){
|
|
|
_id
|
|
|
}
|
|
|
}`
|
|
|
|
|
|
- let variables = { snippet: { title, description, files } ,_id: id };
|
|
|
+ let variables = { snippet: { title, description, files:files }};
|
|
|
|
|
|
let res = await gql(query, variables)
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
+export const actionSnippetUpsert = (title, description, files) => actionPromise("SnippetUpsert", SnippetUpsert(title, description, files))
|
|
|
+
|
|
|
const UserFind = async (_id) => {
|
|
|
let query = `UserFind(query:'[{}])' {
|
|
|
UserFind(query:$query) {
|
|
|
- _id login nick avatar{
|
|
|
+ _id login avatar{
|
|
|
url
|
|
|
}
|
|
|
}
|
|
@@ -85,7 +113,37 @@ const UserFind = async (_id) => {
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+export const actionUserFind = (_id) => actionPromise("UserFind", UserFind(_id))
|
|
|
+
|
|
|
+export const imgFind = async () => {
|
|
|
+ return await gql(`query ImageFind{
|
|
|
+ ImageFind(query:"[{}]"){
|
|
|
+ url owner{
|
|
|
+ nick
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }`)
|
|
|
+}
|
|
|
+
|
|
|
+export const actionImgFind = () => async (dispatch) => {
|
|
|
+ return await dispatch(actionPromise("img", imgFind()));
|
|
|
+}
|
|
|
+
|
|
|
+const setAva = async (idUser, id) => {
|
|
|
+ let query = `mutation setAvatar($idUser:String , $idAvatar:ID){
|
|
|
+ UserUpsert(user:{_id: $idUser, avatar: {_id: $idAvatar}}){
|
|
|
+ _id, avatar{
|
|
|
+ url
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }`
|
|
|
+ let variables = { idUser: idUser, idAvatar: id }
|
|
|
+
|
|
|
+ let res = await gql(query, variables)
|
|
|
+ return res
|
|
|
+}
|
|
|
+
|
|
|
+export const actionSetAva = (idUser, id) => actionPromise("setAva", setAva(idUser, id))
|
|
|
|
|
|
const actionPending = name => ({type: 'PROMISE', status: 'PENDING', name})
|
|
|
const actionResolved = (name, payload) => ({type: 'PROMISE', status: 'RESOLVED', name, payload})
|
|
@@ -104,33 +162,6 @@ const actionPromise = (name, promise) =>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export const actionchangePass = (login, password, newPassword) => actionPromise("changePass", ChangePass(login, password, newPassword))
|
|
|
-const actionAuthLogin = token => ({type: 'LOGIN', token})
|
|
|
-export const actionAuthLogout = () => ({type: 'LOGOUT'})
|
|
|
-const actionLogin = (login, password) => actionPromise("login", log(login, password))
|
|
|
-const actionReg = (login, password) => actionPromise("reg", reg(login, password))
|
|
|
-
|
|
|
-export const actionUserFind = (_id) => actionPromise("UserFind", UserFind(_id))
|
|
|
-export const actionSnippetUpsert = (title, description, files , id) => actionPromise("UserFind", SnippetUpsert(title, description, files , id))
|
|
|
-
|
|
|
-export const actionFullLogin = (login, password) => async(dispatch) => {
|
|
|
-let result = await dispatch(actionLogin(login, password))
|
|
|
- if (result !== null){
|
|
|
- dispatch(actionAuthLogin(result))
|
|
|
- } else {
|
|
|
- alert ('Такой пользователь не существует!')
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-export const actionFullRegister = (login, password) => async(dispatch) => {
|
|
|
- let result = await dispatch(actionReg(login, password))
|
|
|
- if(result?.data?.createUser !== null) {
|
|
|
- dispatch(actionFullLogin(login, password))
|
|
|
- } else {
|
|
|
- alert('Такой пользователь уже существует!')
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
let up = async(file) => {
|
|
|
let formData = new FormData()
|
|
|
formData.append('photo', file)
|
|
@@ -142,3 +173,83 @@ let up = async(file) => {
|
|
|
}
|
|
|
|
|
|
export const actionUploadFile = (file) => actionPromise("upload", up(file))
|
|
|
+
|
|
|
+export const actionFullAvatar = (file) => async (dispatch) => {
|
|
|
+ let result = await dispatch(actionUploadFile(file));
|
|
|
+ await dispatch(actionSetAva(result._id));
|
|
|
+ await dispatch(actionUserFind());
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|