Skip to content
Snippets Groups Projects
Select Git revision
  • Develop
  • master default protected
  • Develop_copy_to_implement_acessibility
  • Develop_copy_to_implement_acessibility_in_admin
  • vinicius_accessibility_from_copy
  • luis_accesibility_before_develop
  • vinicius_accessiblity
  • Fixing_bugs
  • Otimizando_Vinicius
  • Password_recovery_fix
  • fix_admin_bugs_luis
  • luis_gamefication
  • gamificacaoLucas
  • GameficationAdmin
  • fixHomeScreen
  • Fix_perfil
  • fix_remaining_bugs
  • homologa
  • centraliza-axios
  • Gamification
  • v1.2.0
  • v1.1.1
  • v1.1.0
  • V1.0.1
  • V1.0.0
  • V1.0.0-RC
26 results

Avatar.js

Blame
  • Avatar.js 2.83 KiB
    /*Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
    Departamento de Informatica - Universidade Federal do Parana
    
    This file is part of Plataforma Integrada MEC.
    
    Plataforma Integrada MEC is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    Plataforma Integrada MEC is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
    
    You should have received a copy of the GNU Affero General Public License
    along with Plataforma Integrada MEC.  If not, see <http://www.gnu.org/licenses/>.*/
    import React, {useState, useContext, useEffect} from 'react';
    import styled from 'styled-components'
    import { Store } from '../../Store.js';
    import { apiDomain} from '../../env';
    import noAvatar from "../../img/default_profile.png";
    import ModalAlterarAvatar from '../ModalAlterarAvatar/ModalAlterarAvatar.js'
    
    export default function ProfileAvatar (props) {
        // eslint-disable-next-line
        const {state, dispatch} = useContext(Store)
    
        const [currentAvatar, setAvatar] = useState(state.currentUser.avatar)
    
        const [hoverBool, toggleHover] = React.useState(false)
        const handleToggleHover = () => {toggleHover(!hoverBool)}
    
        const [open, toggleOpen] = useState(false)
        const controlModal = () => {toggleOpen(!open)}
    
        useEffect(() => {setAvatar(state.currentUser.avatar)}, [state.currentUser.avatar])
    
        return (
            <>
                <ModalAlterarAvatar
                    open={open}
                    handleClose={controlModal}
                    userAvatar={currentAvatar}
                    id={props.id}
                />
    
                <ProfileAvatarDiv onMouseEnter={handleToggleHover} onMouseLeave={handleToggleHover} onClick={controlModal}>
                    <img src={currentAvatar ? apiDomain + currentAvatar : noAvatar} alt = "user avatar" style={{height : "inherit", width : "inherit", border:"0", verticalAlign:"middle"}}/>
                    <ChangeAvatarDiv  style={ {display : hoverBool ? 'flex' : 'none'}}>
                        <span>Alterar Foto</span>
                    </ChangeAvatarDiv>
                </ProfileAvatarDiv>
    
            </>
        )
    }
    
    const ProfileAvatarDiv = styled.div`
        bottom : -55px;
        left : 60px;
        border-radius : 100%;
        position : absolute;
        width : 150px;
        height : 150px;
        overflow : hidden;
        border : 8px solid #fff;
        outline : 0;
        cursor : pointer;
        background-color : #a5a5a5;
    `
    
    const ChangeAvatarDiv = styled.div`
      height : 40px;
      position: absolute;
      width : 100%;
      bottom : 0;
      display : flex;
      background-color : #000;
      color : #fff;
      justify-content : center;
    `