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';
import Card from '@material-ui/core/Card';

Lucas Eduardo Schoenfelder
committed
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';
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";
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';
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 {getDefaultThumbnail} from './HelperFunctions/getDefaultThumbnail'
import GetIconByName from './UploadPageComponents/GetIconByName'
import {getAxiosConfig} from './HelperFunctions/getAxiosConfig'

Lucas Eduardo Schoenfelder
committed

Lucas Eduardo Schoenfelder
committed
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}]
export default function ResourceCardFunction (props) {
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)
const [publisher, setPublisher] = useState(undefined)

Lucas Eduardo Schoenfelder
committed
useEffect( () => {
//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)
}
}, [])
const handleLike = () => {
let payload = {}
let config = getAxiosConfig()
axios.put( (`${apiUrl}/learning_objects/` + props.id + '/like'),payload, config
).then( (response) => {toggleLiked(!liked)}, (error) => {console.log(error)})
}

Lucas Eduardo Schoenfelder
committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const SlideAnimationContent = () => {
return (
<SlideContentDiv>
<div style={{display:"flex", flex:"1"}}>{/*marginBottom:10px*/}
<AvatarDiv>
<img className="img" src={userAvatar} alt="user avatar"/>
</AvatarDiv>
<EnviadoPor>
Enviado por:
<br/>
<p>{props.author}</p>
</EnviadoPor>
</div>
<TagContainer>
<Grid container spacing={1} justify='safe' style={{height : "inherit"}}>
{
props.tags.map( (tag) =>
<Grid item key={tag.id}>
<span key={tag.id}>{tag.name}</span>
</Grid>
)
}
</Grid>
</TagContainer>
</SlideContentDiv>
)
}
return (
<StyledCard>
<CardDiv>
<CardReaDiv>
<Header onMouseEnter={controlSlide} onMouseLeave={controlSlide}>
{

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

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

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

Lucas Eduardo Schoenfelder
committed
<span>
{props.title}
</span>

Lucas Eduardo Schoenfelder
committed
{
props.published &&
<Rating
name="customized-empty"

Lucas Eduardo Schoenfelder
committed
precision={0.5}
style={{color:"#666"}}
emptyIcon={<StarBorderIcon fontSize="inherit" />}
/>
}
<Footer>
<Type>

Lucas Eduardo Schoenfelder
committed
<span>{label}</span>
</Type>
{
props.published &&
<LikeCounter>
<span>{props.likeCount}</span>
<ButtonNoWidth onClick={handleLike}>
<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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
</CardReaFooter>
}
</CardDiv>
</StyledCard>
)
}
/*---------- USED IN SLIDE DIV ONLY -----------*/
export const TagContainer = styled.div`
display : flex;
flex-direction : row;
width : 100%;
overflow : hidden;
flex : 2;
height : 120px;
span {
background-color : #fff;
height : 20px;
overflow : hidden;
margin : 2px;
padding : 3px 8px;
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 {
text-overflow : ellipsis;
overflow : hidden;
white-space : nowrap;
margin : 0;
}
`
const AvatarDiv = styled.div`
vertical-align : middle;
border : 0;

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

Lucas Eduardo Schoenfelder
committed
border : 0;
vertical-align : middle;
border-radius : 50%;
}
`
const SlideContentDiv = styled.div`
background-color : #ff9226;
padding : 10px;
width : 100%;
height : 100%;
// position : absolute;
// display : flex;
// flex-direction : column;

Lucas Eduardo Schoenfelder
committed
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
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
`
/*--------------------------------------------*/
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
}
`
export const Footer = styled.div`
display : flex;
flex-direction : row;
justify-content : space-between;
`
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;
}
.title {
text-overflow : ellipsis;
overflow : hidden;
margin-bottom : 10px;
font-size : 1.2em;
line-height : 1.1;
max-height : 46px;
color : #666;
}
`
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
`
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);
`