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, apiUrl } from '../env';
import ResourceCardOptions from './ResourceCardOptions'

Lucas Eduardo Schoenfelder
committed
import noAvatar from "../img/default_profile.png";
// import { makeStyles } from '@material-ui/core/styles';

Lucas Eduardo Schoenfelder
committed
import Button from '@material-ui/core/Button';
import styled from 'styled-components'
// import animacao from "../img/laranja/ANIMACAO_SIMULACAO.jpg";
// import apresentacao from "../img/laranja/APRESENTACAO.jpg";
// import aplicativo from "../img/laranja/APP.jpg";
// import audio from "../img/laranja/AUDIO.jpg";
// import vazio from "../img/laranja/EMPTY.jpg";
// import imagem from "../img/laranja/IMAGEM.jpg";
// import grafico from "../img/laranja/INFOGRAFICO.jpg";
// import jogo from "../img/laranja/JOGO.jpg";
// import livro from "../img/laranja/LIVRO_DIGITAL.jpg";
// import mapa from "../img/laranja/MAPA.jpg";
// import outros from "../img/laranja/OUTROS.jpg";
// import software from "../img/laranja/SOFTWARE.jpg";
// import texto from "../img/laranja/TEXTO.jpg";
// import video from "../img/laranja/VIDEO.jpg";

Lucas Eduardo Schoenfelder
committed
import Rating from '@material-ui/lab/Rating';
import StarBorderIcon from '@material-ui/icons/StarBorder';
// import AddIcon from '@material-ui/icons/CreateNewFolder';
// import Video from '@material-ui/icons/OndemandVideo';
// import MoreIcon from '@material-ui/icons/More';

Lucas Eduardo Schoenfelder
committed
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 { getAxiosConfig } from './HelperFunctions/getAxiosConfig'
// import DefaultAvatar from '../../public/img/logo_parceiros/ic_default.png'
// const types = [{label: "Animação", thumb: animacao}, {label: "Apresentação", thumb: apresentacao},
// {label: "Aplicativo" , thumb: aplicativo}, {label: "Áudio", thumb: audio}, {label: "Vazio", thumb: vazio}, {label: "Imagem", thumb: imagem}, {label: "Gráfico", thumb: grafico}, {label: "Jogo", thumb: jogo}, {label: "Livro", thumb: livro}, {label:"Livro digital", thumb: livro}, {label: "Mapa", thumb: mapa}, {label: "Outros", thumb: outros}, {label: "Software Educacional", thumb:software}, {label: "Software", thumb:software}, {label: "Texto", thumb:texto}, {label: "Vídeo", thumb:video}]

Lucas Eduardo Schoenfelder
committed
export default function ResourceCardFunction(props) {
console.log(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
}, [])
const handleLike = () => {
let payload = {}
let config = getAxiosConfig()
axios.put((`${apiUrl}/learning_objects/` + props.id + '/like'), payload, config

Lucas Eduardo Schoenfelder
committed
).then(
(response) => {
console.log(response.data)

Lucas Eduardo Schoenfelder
committed
sessionStorage.setItem('@portalmec/accessToken', response.headers['access-token'])
}
toggleLiked(!liked)
setLikesCount(response.data.count)
},

Lucas Eduardo Schoenfelder
committed
)

Lucas Eduardo Schoenfelder
committed
const SlideAnimationContent = () => {
return (
<SlideContentDiv>

Lucas Eduardo Schoenfelder
committed
<AvatarDiv>
<img className="img" src={userAvatar} alt="user avatar" />

Lucas Eduardo Schoenfelder
committed
</AvatarDiv>
<EnviadoPor>
Enviado por:

Lucas Eduardo Schoenfelder
committed
<p>{props.author}</p>
</EnviadoPor>

Lucas Eduardo Schoenfelder
committed
<TagContainer>
{
props.tags.map((tag) =>
<span key={tag.id}>{tag.name}</span>

Lucas Eduardo Schoenfelder
committed
)
}
</TagContainer>
</SlideContentDiv>
)
}
return (
<StyledCard>
<CardDiv>
<CardReaDiv>
<Header onMouseEnter={controlSlide} onMouseLeave={controlSlide}>
{

Lucas Eduardo Schoenfelder
committed
props.published &&
<Slide direction="left" in={slideIn} timeout={1000}>
<div className={`slideContentLinkAfterActive${slideIn}`} style={{ width: '100%' }}>
<Link to={props.href} className="text" >
{SlideAnimationContent()}
</Link>
</div>
mrp19
committed
</Slide >

Lucas Eduardo Schoenfelder
committed
}
<div className={`slideContentLinkBeforeActive${slideIn}`} style={{width: '100%', height : '100%'}}>
mrp19
committed
<Link to={props.href}>
<img className="img-cover" src={thumbnail} alt="learning object thumbnail" />

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

Lucas Eduardo Schoenfelder
committed
{props.title}

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

Lucas Eduardo Schoenfelder
committed
/>
}
<Footer>
<Type>

Lucas Eduardo Schoenfelder
committed
<span>{label}</span>
</Type>
{
props.published &&
<LikeCounter>

Lucas Eduardo Schoenfelder
committed
<span>{likesCount}</span>
<FavoriteIcon style={{ color: liked ? "red" : "#666" }} />

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

Lucas Eduardo Schoenfelder
committed
</div>
<ResourceCardOptions
learningObjectId={props.id}
downloadableLink={props.downloadableLink}
thumb={props.thumbnail}
title={props.title}

Lucas Eduardo Schoenfelder
committed
</CardReaFooter>
}
</CardDiv>
</StyledCard>
)
}
/*---------- USED IN SLIDE DIV ONLY -----------*/
const HeaderContainer = styled.div`
display: flex;
flex : 1;
`

Lucas Eduardo Schoenfelder
committed
export const TagContainer = styled.div`

Lucas Eduardo Schoenfelder
committed
display : flex;
width : 90%;
overflow : auto;
${'' /* flex : 2; */}

Lucas Eduardo Schoenfelder
committed
height : 120px;
max-height : 120px;
flex-wrap: wrap;
-webkit-box-direction: normal;
flex-direction: row;
${'' /* border : 5px 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;
}
`
export const EnviadoPor = styled.div`
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
}
`
const AvatarDiv = styled.div`
vertical-align : middle;
border : 0;

Lucas Eduardo Schoenfelder
committed
img {
height : 40px !important;
width : 40px !important;

Lucas Eduardo Schoenfelder
committed
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
border : 0;
vertical-align : middle;
border-radius : 50%;
}
`
const SlideContentDiv = styled.div`
background-color : #ff9226;
padding : 10px;
width : 100%;
height : 100%;
`
/*--------------------------------------------*/
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
`
export const CardReaDiv = styled.div`
display : flex;
flex-direction : column;
height : 320px;
width : 272.5px;
margin : 0 auto;
.img-cover {
background-color : #e5e5e5;
height : 100%;
object-fit : cover;
overflow : hidden;
display : block;
background-position : center;
background-size : cover;
width : 100%;
}
`
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;
max-width : 345px;
border-radius : 0;
box-shadow : 0 0 5px 0 rgba(0,0,0,.25);
`