/*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 Grid from '@material-ui/core/Grid'; import CardContent from '@material-ui/core/CardContent'; 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'; //Image Import import { noAvatar } from "ImportImages.js"; export default function ImgMediaCard(props) { const [followedBoolean, setFollowedBoolean] = useState(props.followed) const toggleFollowed = () => { setFollowedBoolean(!followedBoolean) } return ( <StyledCard> <CardDiv className={`${props.contrast}BackColor ${props.contrast}Border ${props.contrast}Text`}> <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 contrast={props.contrast} 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 style={{height: "148px", padding: "0", bottom: "0"}}> <UserInfo> <Link to={props.href} className={`${props.contrast}LinkColor`}> <p className="p1"> {props.name} </p> </Link> <Link to={props.href} className={`${props.contrast}LinkColor`}> <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> </UserInfo> </CardContent> <CardContent style={{padding: "0"}}> <Grid container> <Grid item xs={2}></Grid> { followedBoolean ? ( <> <Grid item xs={8} style={{ display: "flex", justifyContent: "center" }}> <FollowingButton contrast={props.contrast} followedID={props.followerID ? props.followerID : props.followedID} toggleFollowed={toggleFollowed} /> </Grid> <Grid item xs={2} style={{ display: "flex", justifyContent: "flex-start" }}> <Options contrast={props.contrast} followableID={props.followerID ? props.followerID : props.followedID} followed={followedBoolean} toggleFollowed={toggleFollowed} /> </Grid> </> ) : ( <> <Grid item xs={8} style={{ display: "flex", justifyContent: "center" }}> <FollowButton contrast={props.contrast} followerID={props.followedID ? props.followedID : props.followerID} toggleFollowed={toggleFollowed} /> </Grid> <Grid item xs={2} style={{ display: "flex", justifyContent: "flex-start" }}> <Options contrast={props.contrast} followableID={props.followedID ? props.followedID : props.followerID} followed={followedBoolean} toggleFollowed={toggleFollowed} /> </Grid> </> ) } </Grid> </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` text-align : start; font-family : 'Roboto', sans serif; ` /*----------------------------------------------------------------------------*/ /*Override Material UI styling -----------------------------------------------*/ const StyledCardMedia = styled(CardMedia)` height : 100%; width : 270.5px; 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; a { 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; `