Repair user info avatar error

This commit is contained in:
Qolzam
2017-07-09 08:35:33 +04:30
parent a23a16ef03
commit f170c770b2
3 changed files with 60 additions and 41 deletions

View File

@@ -51,7 +51,8 @@ export var dbSignup = (user) => {
dispatch(globalActions.showNotificationRequest()) dispatch(globalActions.showNotificationRequest())
return firebaseAuth().createUserWithEmailAndPassword(user.email, user.password).then((signupResult) => { return firebaseAuth().createUserWithEmailAndPassword(user.email, user.password).then((signupResult) => {
firebaseRef.child(`users/${signupResult.uid}/info`).set({ firebaseRef.child(`users/${signupResult.uid}/info`).set({
...user ...user,
avatar:'noImage'
}).then((result) => { }).then((result) => {
dispatch(globalActions.showNotificationSuccess()) dispatch(globalActions.showNotificationSuccess())

View File

@@ -1,5 +1,5 @@
// - Import react components // - Import react components
import {firebaseRef} from 'app/firebase/' import { firebaseRef } from 'app/firebase/'
// - Import action types // - Import action types
import * as types from 'actionTypes' import * as types from 'actionTypes'
@@ -24,8 +24,14 @@ export const dbGetUserInfo = () => {
return userInfoRef.once('value').then((snapshot) => { return userInfoRef.once('value').then((snapshot) => {
var userInfo = snapshot.val() || {}; var userInfo = snapshot.val() || {};
dispatch(addUserInfo(uid,userInfo)) dispatch(addUserInfo(uid, {
},error => console.log(error)); avatar: userInfo.avatar,
email: userInfo.email,
fullName: userInfo.fullName,
banner: userInfo.banner,
tagLine: userInfo.tagLine
}))
}, error => console.log(error));
} }
} }
@@ -35,24 +41,30 @@ export const dbGetUserInfo = () => {
* Get user info from database * Get user info from database
* @param {string} uid * @param {string} uid
*/ */
export const dbGetUserInfoByUserId = (uid,sw) => { export const dbGetUserInfoByUserId = (uid, sw) => {
return (dispatch, getState) => { return (dispatch, getState) => {
if (uid) { if (uid) {
var userInfoRef = firebaseRef.child(`users/${uid}/info`); var userInfoRef = firebaseRef.child(`users/${uid}/info`);
return userInfoRef.once('value').then((snapshot) => { return userInfoRef.once('value').then((snapshot) => {
var userInfo = snapshot.val() || {}; var userInfo = snapshot.val() || {};
dispatch(addUserInfo(uid,userInfo)) dispatch(addUserInfo(uid, {
avatar: userInfo.avatar,
email: userInfo.email,
fullName: userInfo.fullName,
banner: userInfo.banner,
tagLine: userInfo.tagLine
}))
switch (sw) { switch (sw) {
case 'header': case 'header':
dispatch(globalActions.setHeaderTitle(userInfo.fullName)) dispatch(globalActions.setHeaderTitle(userInfo.fullName))
break; break;
default: default:
break; break;
} }
},error => console.log(error)); }, error => console.log(error));
} }
} }
@@ -63,30 +75,30 @@ export const dbGetUserInfoByUserId = (uid,sw) => {
* @param {object} newInfo * @param {object} newInfo
*/ */
export const dbUpdateUserInfo = (newInfo) => { export const dbUpdateUserInfo = (newInfo) => {
return (dispatch,getState) => { return (dispatch, getState) => {
// Get current user id // Get current user id
var uid = getState().authorize.uid var uid = getState().authorize.uid
// Write the new data simultaneously in the list // Write the new data simultaneously in the list
let updates = {}; let updates = {};
let info = getState().user.info[uid] let info = getState().user.info[uid]
let updatedInfo = { let updatedInfo = {
avatar: newInfo.avatar || info.avatar || '', avatar: newInfo.avatar || info.avatar || '',
banner:newInfo.banner || info.banner || '', banner: newInfo.banner || info.banner || '',
email: newInfo.email || info.email || '', email: newInfo.email || info.email || '',
fullName: newInfo.fullName || info.fullName || '', fullName: newInfo.fullName || info.fullName || '',
tagLine: newInfo.tagLine || info.tagLine || '' tagLine: newInfo.tagLine || info.tagLine || ''
} }
updates[`users/${uid}/info`] = updatedInfo updates[`users/${uid}/info`] = updatedInfo
return firebaseRef.update(updates).then((result) => { return firebaseRef.update(updates).then((result) => {
dispatch(updateUserInfo(uid,updatedInfo)) dispatch(updateUserInfo(uid, updatedInfo))
dispatch(closeEditProfile()) dispatch(closeEditProfile())
}, (error) => { }, (error) => {
dispatch(globalActions.showErrorMessage(error.message)) dispatch(globalActions.showErrorMessage(error.message))
}) })
} }
} }
@@ -100,16 +112,22 @@ export const dbGetPeopleInfo = () => {
return peopleRef.once('value').then((snapshot) => { return peopleRef.once('value').then((snapshot) => {
let people = snapshot.val() || {}; let people = snapshot.val() || {};
let parsedPeople = {}; let parsedPeople = {};
Object.keys(people).forEach((userId) => { Object.keys(people).forEach((userId) => {
if(userId !== uid){ if (userId !== uid) {
parsedPeople[userId]={ let userInfo = people[userId].info
...people[userId].info parsedPeople[userId] = {
}} avatar: userInfo.avatar,
email: userInfo.email,
fullName: userInfo.fullName,
banner: userInfo.banner,
tagLine: userInfo.tagLine
}
}
}) })
dispatch(addPeopleInfo(parsedPeople)) dispatch(addPeopleInfo(parsedPeople))
},error => console.log(error)); }, error => console.log(error));
} }
} }
@@ -123,10 +141,10 @@ export const dbGetPeopleInfo = () => {
* @param {string} uid is the user identifier * @param {string} uid is the user identifier
* @param {object} info is the information about user * @param {object} info is the information about user
*/ */
export const addUserInfo = (uid,info) => { export const addUserInfo = (uid, info) => {
return{ return {
type: types.ADD_USER_INFO, type: types.ADD_USER_INFO,
payload: {uid,info} payload: { uid, info }
} }
} }
@@ -135,7 +153,7 @@ export const addUserInfo = (uid,info) => {
* @param {[object]} infoList is the lst of information about users * @param {[object]} infoList is the lst of information about users
*/ */
export const addPeopleInfo = (infoList) => { export const addPeopleInfo = (infoList) => {
return{ return {
type: types.ADD_PEOPLE_INFO, type: types.ADD_PEOPLE_INFO,
payload: infoList payload: infoList
} }
@@ -146,11 +164,11 @@ export const addPeopleInfo = (infoList) => {
* @param {string} uid is the user identifier * @param {string} uid is the user identifier
* @param {object} info is the information about user * @param {object} info is the information about user
*/ */
export const updateUserInfo = (uid,info) => { export const updateUserInfo = (uid, info) => {
return{ return {
type: types.UPDATE_USER_INFO, type: types.UPDATE_USER_INFO,
payload: {uid,info} payload: { uid, info }
} }
} }
/** /**
@@ -158,7 +176,7 @@ export const addPeopleInfo = (infoList) => {
* @param {object} info * @param {object} info
*/ */
export const userInfo = (info) => { export const userInfo = (info) => {
return{ return {
type: types.USER_INFO, type: types.USER_INFO,
info info
} }
@@ -175,7 +193,7 @@ export const clearAllData = () => {
* Open edit profile * Open edit profile
*/ */
export const openEditProfile = () => { export const openEditProfile = () => {
return{ return {
type: types.OPEN_EDIT_PROFILE type: types.OPEN_EDIT_PROFILE
} }
@@ -185,7 +203,7 @@ export const openEditProfile = () => {
* Close edit profile * Close edit profile
*/ */
export const closeEditProfile = () => { export const closeEditProfile = () => {
return{ return {
type: types.CLOSE_EDIT_PROFILE type: types.CLOSE_EDIT_PROFILE
} }

View File

@@ -6,7 +6,7 @@
width: 200px; width: 200px;
position: fixed!important; position: fixed!important;
z-index: 1; z-index: 1;
overflow: auto overflow: hidden;
} }
.sidebar__large { .sidebar__large {