|
@@ -73,6 +73,36 @@ const actionLoadFile = (file) => {
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+const actionAboutMe = () => {
|
|
|
|
+ let _id = jwtDecode(localStorage.authToken).sub.id
|
|
|
|
+ return (
|
|
|
|
+ actionPromise('aboutUser', gql(`
|
|
|
|
+ query($userId: String!) {
|
|
|
|
+ UserFindOne(query: $userId){
|
|
|
|
+ login, _id, avatar {_id, url, originalFileName}
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ `, { userId: JSON.stringify([{_id}]) }))
|
|
|
|
+ )
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const actionSetAvatar = (file) =>
|
|
|
|
+ async (dispatch, getState) => {
|
|
|
|
+ await dispatch(actionLoadFile(file))
|
|
|
|
+ let picId = getState().promise?.loadFile?.payload?._id
|
|
|
|
+ let userId = jwtDecode(localStorage.authToken).sub.id
|
|
|
|
+ await dispatch(actionPromise('setAvatar', gql(`
|
|
|
|
+ mutation {
|
|
|
|
+ UserUpsert(user:{_id: "${userId}", avatar: {_id: "${picId}"}}){
|
|
|
|
+ _id, login, avatar{
|
|
|
|
+ _id, url
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ `)))
|
|
|
|
+ dispatch(actionAboutMe())
|
|
|
|
+ }
|
|
|
|
+
|
|
function promiseReducer(state={}, {type, name, status, payload, error}){
|
|
function promiseReducer(state={}, {type, name, status, payload, error}){
|
|
if (type === 'PROMISE'){
|
|
if (type === 'PROMISE'){
|
|
return {
|
|
return {
|
|
@@ -92,10 +122,9 @@ const store = createStore(
|
|
)
|
|
)
|
|
store.subscribe(() => console.log(store.getState()))
|
|
store.subscribe(() => console.log(store.getState()))
|
|
|
|
|
|
-function MyDropzone({onLoad}) {
|
|
|
|
|
|
+function MyDropzone({uploadAvatar, userData, onLoad}) {
|
|
const onDrop = useCallback(acceptedFiles => {
|
|
const onDrop = useCallback(acceptedFiles => {
|
|
- //console.log(acceptedFiles)
|
|
|
|
- onLoad(acceptedFiles[0])
|
|
|
|
|
|
+ uploadAvatar(acceptedFiles[0])
|
|
}, [])
|
|
}, [])
|
|
const {getRootProps, getInputProps, isDragActive} = useDropzone({onDrop})
|
|
const {getRootProps, getInputProps, isDragActive} = useDropzone({onDrop})
|
|
|
|
|
|
@@ -111,7 +140,7 @@ function MyDropzone({onLoad}) {
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
-const ConnectDropzone = connect(null, {onLoad: actionLoadFile})(MyDropzone)
|
|
|
|
|
|
+const ConnectDropzone = connect(null, {uploadAvatar: actionSetAvatar, onLoad: actionLoadFile, userData: actionAboutMe})(MyDropzone)
|
|
|
|
|
|
function App() {
|
|
function App() {
|
|
return (
|
|
return (
|