Skip to content
Snippets Groups Projects
ContactCard.js 7.29 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 } from 'react';
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import noAvatar from "../img/default_profile.png";
import CardMedia from '@material-ui/core/CardMedia';
import styled from 'styled-components'
import Options from './ContactCardOptions.js'
import FollowButton from './ContactButtons/FollowButton.js'
import FollowingButton from './ContactButtons/FollowingButton.js'
import FollowersCountButton from './ContactButtons/FollowersCountButton.js'
import { Link } from 'react-router-dom';

export default function ImgMediaCard(props) {

    const [followedBoolean, setFollowedBoolean] = useState(props.followed)
    const toggleFollowed = () => { setFollowedBoolean(!followedBoolean) }
    return (
        <StyledCard>
            <CardDiv>
                <CardAreaDiv>
                    {/*Top part of contat card (background image, number of followers and avatar)*/}
                    <Header>
                        <StyledCardMedia image={props.cover}>
                            <div style={{ display: "flex", backgroundColor: "inherit", float: "right" }}>
                                <Link to={props.href} style={{textDecoration : "none"}}>
                                    <FollowersCountButton followCount={props.follow_count} />
                                </Link>
                                <Link to={props.href}>
                                    <AvatarDiv>
                                        <img src={props.avatar ? props.avatar : noAvatar} alt='user avatar'
                                            style={{ height: "100%", width: "100%", borderRadius: "50%" }} />
                                    </AvatarDiv>
                                </Link>
                            </div>
                        </StyledCardMedia>
                    </Header>

                    {/*Rest of the card content. Button to be rendered depends on whether the contact is followed by the user*/}
                    <CardContent>
                        <UserInfo>
                            <Link to={props.href}>
                                <p className="p1">
                                    {props.name}
                                </p>
                            </Link>

                            <Link to={props.href}>
                                <span style={{ fontSize: "14px", fontWeight: "normal" }}>
                                    <b>{props.numCollections}</b> {props.numCollections !== 1 ? "Coleções" : "Coleção"} | <b>{props.numLearningObjects}</b> {props.numLearningObjects !== 1 ? "Recursos" : "Recurso"}
                                </span>
                            </Link>
                            <div style={{ display: "flex", justifyContent: "center" }}>
                                {
                                    followedBoolean ?
                                        (
                                            <React.Fragment>
                                                <FollowingButton
                                                    followedID={props.followerID ? props.followerID : props.followedID}
                                                    toggleFollowed={toggleFollowed} />

                                                <Options
                                                    followableID={props.followerID ? props.followerID : props.followedID}
                                                    followed={followedBoolean}
                                                    toggleFollowed={toggleFollowed} />
                                            </React.Fragment>
                                        )
                                        :
                                        (
                                            <React.Fragment>
                                                <FollowButton
                                                    followerID={props.followedID ? props.followedID : props.followerID}
                                                    toggleFollowed={toggleFollowed} />

                                                <Options
                                                    followableID={props.followedID ? props.followedID : props.followerID}
                                                    followed={followedBoolean}
                                                    toggleFollowed={toggleFollowed} />
                                            </React.Fragment>
                                        )
                                }

                            </div>
                        </UserInfo>
                    </CardContent>
                </CardAreaDiv>
            </CardDiv>
        </StyledCard>
    );
}

/*Controls top part of Card*/
const Header = styled.div`
    display : flex;
    height : 152px;
    position : relative;
`

/* Had to create these classes so I could avoid using card action Area -------*/
export const CardAreaDiv = styled.div`
    display : flex;
    flex-direction : column;
    height : 360px;
    width : 272.5px;
    margin : 0 auto;
`
export const CardDiv = styled.div`
    background-color : #fff;
    text-align : start;
    font-family : 'Roboto', sans serif;
    color : #666;
`
/*----------------------------------------------------------------------------*/



/*Override Material UI styling -----------------------------------------------*/
const StyledCardMedia = styled(CardMedia)`
    height : 100%;
    width : 100%;
    background-size : cover;
    background-position : center;

`
const StyledCard = styled(Card)`
    width : 272.5px;
    max-height : 380px;
    margin-top : 10px;
    margin-bottom : 10px;
    max-width : 345px;
    border-radius : 0;
    box-shadow : 0 0 5px 0 rgba(0,0,0,.25) !important;
`
/*----------------------------------------------------------------------------*/


const UserInfo = styled.div`
    text-align : center;
    margin-top : 50px;
    color : #666;

    a {
        text-decoration : none !important;
        color : #666;
    }

    .p1 {
        font-size : 17px;
        margin : 0 0 10px;
        overflow : hidden;
        text-overflow : ellipsis;
        white-space : nowrap;
    }
`

/*Rounded div to be used with avatar pic*/
const AvatarDiv = styled.div`
    border-radius : 100%;
    left : 50%;
    position : absolute;
    -webkit-transform : translateX(-50%);
    transform : translateX(-50%);
    top : 65px;
    height : 126px;
    width : 126px;
    border : 2px solid #fff;
`