Newer
Older

Lucas Eduardo Schoenfelder
committed
/*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, useEffect } from 'react';

Lucas Eduardo Schoenfelder
committed
import Card from '@material-ui/core/Card';
import { apiDomain } from '../env';
import ResourceCardOptions from './ResourceCardOptions'

Lucas Eduardo Schoenfelder
committed
import noAvatar from "../img/default_profile.png";
import Button from '@material-ui/core/Button';
import styled from 'styled-components'
import Rating from '@material-ui/lab/Rating';
import StarBorderIcon from '@material-ui/icons/StarBorder';
import FavoriteIcon from '@material-ui/icons/Favorite';
import ButtonGuardarColecao from './ButtonGuardarColecao.js'
import Slide from '@material-ui/core/Slide';
import Grid from '@material-ui/core/Grid';
import { Link } from 'react-router-dom';
import { getDefaultThumbnail } from './HelperFunctions/getDefaultThumbnail'
import GetIconByName from './UploadPageComponents/GetIconByName'
import { putRequest } from './HelperFunctions/getAxiosConfig'

Lucas Eduardo Schoenfelder
committed
export default function ResourceCardFunction(props) {

Lucas Eduardo Schoenfelder
committed
const [thumbnail, setThumbnail] = useState(null)
const [label, setLabel] = useState(props.type)

Lucas Eduardo Schoenfelder
committed
const [userAvatar, setUserAvatar] = useState(noAvatar)
const [slideIn, setSlide] = useState(false)
const controlSlide = () => { setSlide(!slideIn) }
const [liked, toggleLiked] = useState(props.liked)

Lucas Eduardo Schoenfelder
committed
const [likesCount, setLikesCount] = useState(props.likeCount)

Lucas Eduardo Schoenfelder
committed

Lucas Eduardo Schoenfelder
committed
//decide which thumbnail to use
if (props.thumbnail) {
setThumbnail(`${apiDomain}` + props.thumbnail)
}
else {
setThumbnail(getDefaultThumbnail(label))

Lucas Eduardo Schoenfelder
committed
}
if (props.avatar) {
setUserAvatar(`${apiDomain}` + props.avatar)
}
else {
setUserAvatar(require('../img/logo_parceiros/ic_default.png'))
}

Lucas Eduardo Schoenfelder
committed
}, [])
function handleSuccessLike(data) {
toggleLiked(!liked)
setLikesCount(data.count)
}
const handleLike = () => {
const url = `/learning_objects/${props.id}/like/`

Lucas Eduardo Schoenfelder
committed
putRequest(url, {}, handleSuccessLike, (error) => { console.log(error) })

Lucas Eduardo Schoenfelder
committed
const SlideAnimationContent = () => {
return (
<SlideContentDiv>
<div style={{ padding: 7 }}>
<HeaderContainer container="row" justify="flex-start" alignItems="center" >{/*marginBottom:10px*/}
<AvatarDiv item xs={2}>
<img className="img" src={userAvatar} alt="user avatar" />
</AvatarDiv>
<EnviadoPor item xs={10}>
Enviado por:
<p>{props.author}</p>
</EnviadoPor>
</HeaderContainer>
{
props.tags ?
<TagContainer container direction="row">
{
props.tags.map((tag) =>
<Grid item key={tag.id}>
<span >{tag.name}</span>
</Grid>
)
}
</TagContainer> :
null
}

Lucas Eduardo Schoenfelder
committed
</div>
</SlideContentDiv>
)
}
return (
<StyledCard>
<CardDiv>
<CardReaDiv>
<Header onMouseEnter={controlSlide} onMouseLeave={controlSlide}>
{
<Slide direction="left" in={slideIn} timeout={1000}>
<div className={`slideContentLinkAfterActive${slideIn}`}>
<Link to={props.href} className="text" >
{SlideAnimationContent()}
</Link>
</div>
mrp19
committed
</Slide >

Lucas Eduardo Schoenfelder
committed
}
<div className={`slideContentLinkBeforeActive${slideIn}`} style={{ height: '100%' }}>
<img className="img-cover" src={thumbnail} alt="learning object thumbnail" style={{ width: "272.5px" }} />

Lucas Eduardo Schoenfelder
committed
</Header>
<Description>
<Link to={props.href} className="text" style={{ height: '45px' }}> {/*add link to learningObject*/}

Lucas Eduardo Schoenfelder
committed
{props.title}
<Rating
name="customized-empty"
value={props.rating}
readOnly
style={{ color: "#666" }}
emptyIcon={<StarBorderIcon fontSize="inherit" />}
/>

Lucas Eduardo Schoenfelder
committed
<Footer>
<Type>

Lucas Eduardo Schoenfelder
committed
<span>{label}</span>
</Type>
<LikeCounter>
<span>{likesCount}</span>
<ButtonNoWidth onClick={handleLike}>
<FavoriteIcon style={{ color: liked ? "red" : "#666" }} />
</ButtonNoWidth>
</LikeCounter>

Lucas Eduardo Schoenfelder
committed
</Footer>
</Description>
</CardReaDiv>
<CardReaFooter>
<div style={{ display: "flex", height: "100%" }}>
<ButtonGuardarColecao thumb={props.thumbnail} title={props.title} recursoId={props.id}
</div>
<ResourceCardOptions
learningObjectId={props.id}
downloadableLink={props.downloadableLink}
thumb={props.thumbnail}
title={props.title}
/>
</CardReaFooter>

Lucas Eduardo Schoenfelder
committed
</CardDiv>
</StyledCard>
)
}
/*---------- USED IN SLIDE DIV ONLY -----------*/

Lucas Eduardo Schoenfelder
committed
height : 120px ;
overflow-y : hidden;
${'' /* border : 2px solid red; */}

Lucas Eduardo Schoenfelder
committed
span {

Lucas Eduardo Schoenfelder
committed
background-color : #fff;
display : flex;
justify-content : center;
align-items : center;
height : 22px;
tet-align : center;
margin: 3px;
-webkit-box-direction: normal;

Lucas Eduardo Schoenfelder
committed
overflow : hidden;

Lucas Eduardo Schoenfelder
committed
border-radius : 10px;
color : #666;
font-size : 11px;
}
`

Lucas Eduardo Schoenfelder
committed
display : inline-block;
padding-left : 10px;
overflow : hidden;
color : #fff;
padding-right : 1em;
p {
margin : 0;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
overflow: hidden;

Lucas Eduardo Schoenfelder
committed
}
`

Lucas Eduardo Schoenfelder
committed
vertical-align : middle;
border : 0;

Lucas Eduardo Schoenfelder
committed
img {

Lucas Eduardo Schoenfelder
committed
border : 0;
vertical-align : middle;
border-radius : 50%;
}
`
const SlideContentDiv = styled.div`
background-color : #ff9226;
${'' /* padding : 10px; */}
width : 272.5px;
height : 189px;

Lucas Eduardo Schoenfelder
committed
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
`
/*--------------------------------------------*/
const CardReaFooter = styled.div`
height : 60px;
display : flex;
justify-content : space-between;
border-top : 1px solid #e5e5e5;
border-bottom : 1px solid #e5e5e5;
align-items : center;
padding : 0 15px 0 15px;
`
export const ButtonNoWidth = styled(Button)`
max-width : 24px !important;
width : 24px !important;
min-width : 24px !important;
max-height : 24px !important;
padding : 0 !important;
background-color : #fff !important;
color : #a5a5a5 !important;
border : 0 !important;
.MuiButton-root {
width : 24px !important;
min-width : 12px !important;
}
.MuiSvgIcon-root {
padding-right : 0 !important;
}
.MuiButton-label {
padding-left : 4px !important;
}
`
export const LikeCounter = styled.div`
font-size : 14px;
.btn-like {
padding : 0 !important;
background-color : #fff !important;
border : 0 !important;
min-width : min-content;
}
.MuiSvgIcon-root {
font-size : 21px;
vertical-align : middle;
padding-right : .4em;
}
`
const Type = styled.div`
line-height : 1;
.icon {
height : 27px;
width : 27px;

Lucas Eduardo Schoenfelder
committed
padding-right : .4em;
vertical-align : middle
align-self : center;
.st1 {
fill : #ff7f00;
}

Lucas Eduardo Schoenfelder
committed
}
`
export const Footer = styled.div`
display : flex;
flex-direction : row;
justify-content : space-between;

Lucas Eduardo Schoenfelder
committed
`
const Description = styled.div`
display : flex;
flex : 1;
background-color : #fff;
flex-direction : column;
justify-content: space-between;
padding : 15px;
a {
text-decoration : none !important;
color : inherit;
}
`
const Title = styled.span`
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
color : #666;

Lucas Eduardo Schoenfelder
committed
`
export const Header = styled.div`
display : flex;
flex : 2;
position : relative;
overflow : hidden;

Lucas Eduardo Schoenfelder
committed
a {
text-decoration : none !important;
}

Lucas Eduardo Schoenfelder
committed
`
export const CardReaDiv = styled.div`
display : flex;
flex-direction : column;
height : 320px;

Lucas Eduardo Schoenfelder
committed
margin : 0 auto;
.img-cover {
background-color : #e5e5e5;
height : 100%;
object-fit : cover;
overflow : hidden;
display : block;
background-position : center;
background-size : cover;

Lucas Eduardo Schoenfelder
committed
}
`
export const CardDiv = styled.div`
background-color : #fff;
text-align : start;
font-family : 'Roboto', sans serif;
color : #666;
`
export const StyledCard = styled(Card)`
width : 272.5px;
max-height : 380px;
margin-top : 10px;
margin-bottom : 10px;

Lucas Eduardo Schoenfelder
committed
border-radius : 0;
box-shadow : 0 0 5px 0 rgba(0,0,0,.25);
`