From f170c770b24565faf97ba68e49c5678043fd0885 Mon Sep 17 00:00:00 2001 From: Qolzam Date: Sun, 9 Jul 2017 08:35:33 +0430 Subject: [PATCH] Repair user info avatar error --- app/actions/authorizeActions.jsx | 3 +- app/actions/userActions.jsx | 96 +++++++++++++++++------------ app/styles/components/_sidebar.scss | 2 +- 3 files changed, 60 insertions(+), 41 deletions(-) diff --git a/app/actions/authorizeActions.jsx b/app/actions/authorizeActions.jsx index 52d2234..d1ae54d 100644 --- a/app/actions/authorizeActions.jsx +++ b/app/actions/authorizeActions.jsx @@ -51,7 +51,8 @@ export var dbSignup = (user) => { dispatch(globalActions.showNotificationRequest()) return firebaseAuth().createUserWithEmailAndPassword(user.email, user.password).then((signupResult) => { firebaseRef.child(`users/${signupResult.uid}/info`).set({ - ...user + ...user, + avatar:'noImage' }).then((result) => { dispatch(globalActions.showNotificationSuccess()) diff --git a/app/actions/userActions.jsx b/app/actions/userActions.jsx index 0199428..6fd925c 100644 --- a/app/actions/userActions.jsx +++ b/app/actions/userActions.jsx @@ -1,5 +1,5 @@ // - Import react components -import {firebaseRef} from 'app/firebase/' +import { firebaseRef } from 'app/firebase/' // - Import action types import * as types from 'actionTypes' @@ -24,8 +24,14 @@ export const dbGetUserInfo = () => { return userInfoRef.once('value').then((snapshot) => { var userInfo = snapshot.val() || {}; - dispatch(addUserInfo(uid,userInfo)) - },error => console.log(error)); + dispatch(addUserInfo(uid, { + 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 * @param {string} uid */ -export const dbGetUserInfoByUserId = (uid,sw) => { +export const dbGetUserInfoByUserId = (uid, sw) => { return (dispatch, getState) => { if (uid) { var userInfoRef = firebaseRef.child(`users/${uid}/info`); return userInfoRef.once('value').then((snapshot) => { 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) { case 'header': - dispatch(globalActions.setHeaderTitle(userInfo.fullName)) - + dispatch(globalActions.setHeaderTitle(userInfo.fullName)) + break; - + default: break; } - },error => console.log(error)); + }, error => console.log(error)); } } @@ -63,30 +75,30 @@ export const dbGetUserInfoByUserId = (uid,sw) => { * @param {object} newInfo */ export const dbUpdateUserInfo = (newInfo) => { - return (dispatch,getState) => { + return (dispatch, getState) => { - // Get current user id + // Get current user id var uid = getState().authorize.uid // Write the new data simultaneously in the list let updates = {}; let info = getState().user.info[uid] let updatedInfo = { - avatar: newInfo.avatar || info.avatar || '', - banner:newInfo.banner || info.banner || '', - email: newInfo.email || info.email || '', - fullName: newInfo.fullName || info.fullName || '', - tagLine: newInfo.tagLine || info.tagLine || '' + avatar: newInfo.avatar || info.avatar || '', + banner: newInfo.banner || info.banner || '', + email: newInfo.email || info.email || '', + fullName: newInfo.fullName || info.fullName || '', + tagLine: newInfo.tagLine || info.tagLine || '' } updates[`users/${uid}/info`] = updatedInfo return firebaseRef.update(updates).then((result) => { - - dispatch(updateUserInfo(uid,updatedInfo)) + + dispatch(updateUserInfo(uid, updatedInfo)) dispatch(closeEditProfile()) }, (error) => { dispatch(globalActions.showErrorMessage(error.message)) }) - } + } } @@ -100,16 +112,22 @@ export const dbGetPeopleInfo = () => { return peopleRef.once('value').then((snapshot) => { let people = snapshot.val() || {}; - let parsedPeople = {}; - Object.keys(people).forEach((userId) => { - if(userId !== uid){ - parsedPeople[userId]={ - ...people[userId].info - }} + let parsedPeople = {}; + Object.keys(people).forEach((userId) => { + if (userId !== uid) { + let userInfo = people[userId].info + parsedPeople[userId] = { + avatar: userInfo.avatar, + email: userInfo.email, + fullName: userInfo.fullName, + banner: userInfo.banner, + tagLine: userInfo.tagLine + } + } - }) + }) 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 {object} info is the information about user */ -export const addUserInfo = (uid,info) => { - return{ +export const addUserInfo = (uid, info) => { + return { 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 */ export const addPeopleInfo = (infoList) => { - return{ + return { type: types.ADD_PEOPLE_INFO, payload: infoList } @@ -146,11 +164,11 @@ export const addPeopleInfo = (infoList) => { * @param {string} uid is the user identifier * @param {object} info is the information about user */ - export const updateUserInfo = (uid,info) => { - return{ - type: types.UPDATE_USER_INFO, - payload: {uid,info} - } +export const updateUserInfo = (uid, info) => { + return { + type: types.UPDATE_USER_INFO, + payload: { uid, info } + } } /** @@ -158,7 +176,7 @@ export const addPeopleInfo = (infoList) => { * @param {object} info */ export const userInfo = (info) => { - return{ + return { type: types.USER_INFO, info } @@ -175,7 +193,7 @@ export const clearAllData = () => { * Open edit profile */ export const openEditProfile = () => { - return{ + return { type: types.OPEN_EDIT_PROFILE } @@ -185,7 +203,7 @@ export const openEditProfile = () => { * Close edit profile */ export const closeEditProfile = () => { - return{ + return { type: types.CLOSE_EDIT_PROFILE } diff --git a/app/styles/components/_sidebar.scss b/app/styles/components/_sidebar.scss index 98f4817..ff4c1b0 100644 --- a/app/styles/components/_sidebar.scss +++ b/app/styles/components/_sidebar.scss @@ -6,7 +6,7 @@ width: 200px; position: fixed!important; z-index: 1; - overflow: auto + overflow: hidden; } .sidebar__large {