From 922f8f3b51b60fa5e45e5fd06d06b25986036ee3 Mon Sep 17 00:00:00 2001 From: Benjamin Gammaire Date: Fri, 22 Nov 2019 18:10:20 +0100 Subject: [PATCH] use only profile badge in Avatar component - remove useless states - rename fn for clarity --- src/components/Avatar/index.tsx | 37 +++++++-------------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/src/components/Avatar/index.tsx b/src/components/Avatar/index.tsx index 5e03b2ad7c..d7d969b46d 100644 --- a/src/components/Avatar/index.tsx +++ b/src/components/Avatar/index.tsx @@ -2,8 +2,7 @@ import React from 'react' import { Image, ImageProps } from 'rebass' import { inject, observer } from 'mobx-react' -import { UserStore, getUserAvatar } from 'src/stores/User/user.store' -import { ProfileTypeLabel, IProfileType } from 'src/models/user_pp.models' +import { ProfileTypeLabel } from 'src/models/user_pp.models' import Workspace from 'src/pages/User/workspace/Workspace' interface IProps extends ImageProps { @@ -12,14 +11,8 @@ interface IProps extends ImageProps { profileType?: ProfileTypeLabel } -interface IInjected extends IProps { - userStore: UserStore -} - interface IState { - avatarUrl?: string - fallbackBadge?: string - showFallback?: boolean + badgeProfileType?: string } @inject('userStore') @@ -29,35 +22,20 @@ export class Avatar extends React.Component { super(props) this.state = {} } - get injected() { - return this.props as IInjected - } // subscribe/unsubscribe from specific user profile message when // user updates their avatar (same url so by default will now be aware of change) componentDidMount() { - this.getAvatar(this.props.userName) - this.getFallbackImage(this.props.profileType) + this.getProfileTypeBadge(this.props.profileType) } - public getFallbackImage(type?: ProfileTypeLabel) { + public getProfileTypeBadge(type?: ProfileTypeLabel) { const img = Workspace.findWorkspaceBadge(type, true) - this.setState({ fallbackBadge: img }) + this.setState({ badgeProfileType: img }) } - - async getAvatar(userName: string) { - const url = getUserAvatar(userName) - console.log('avatar', url) - this.setState({ avatarUrl: url }) - } - render() { const { width } = this.props - const { avatarUrl, fallbackBadge } = this.state - - const addFallbackSrc = (ev: any) => { - ev.target.src = fallbackBadge - } + const { badgeProfileType } = this.state return ( <> @@ -66,8 +44,7 @@ export class Avatar extends React.Component { width={width ? width : 40} height={width ? width : 40} sx={{ borderRadius: '25px' }} - src={avatarUrl} - onError={addFallbackSrc} + src={badgeProfileType} /> )