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, useContext, useEffect } from 'react';
import { Store } from '../Store.js'

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

Lucas Eduardo Schoenfelder
committed
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 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'
import SignUpModal from './SignUpModal'
import LoginModal from './LoginModal.js'
import Snackbar from '@material-ui/core/Snackbar';
import MuiAlert from '@material-ui/lab/Alert';

Lucas Eduardo Schoenfelder
committed
//Image Import
import { noAvatar } from "ImportImages.js";
import { IcDefault } from "ImportImages.js";
export default function ResourceCardFunction(props) {
const { state } = useContext(Store)

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
const [signUpOpen, setSignUp] = useState(false)
const [loginOpen, setLogin] = useState(false)
const [successfulLoginOpen, handleSuccessfulLogin] = useState(false)
function Alert(props) {
return <MuiAlert elevation={6} variant="filled" {...props} />;
}

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)
}
setUserAvatar(IcDefault)

Lucas Eduardo Schoenfelder
committed
}, [])
function handleSuccessLike(data) {
toggleLiked(!liked)
setLikesCount(data.count)
}
const handleLike = () => {
if (state.currentUser.id)
putRequest(`/learning_objects/${props.id}/like/`, {}, handleSuccessLike, (error) => { console.log(error) })
else
handleLogin()
const handleLogin = () => {
setLogin(!loginOpen)
}
const handleSignUp = () => {
setSignUp(!signUpOpen)
}
function toggleLoginSnackbar(reason) {
if (reason === 'clickaway') {
return;
}
handleSuccessfulLogin(false);
}

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 (
<React.Fragment>
<SignUpModal open={signUpOpen} handleClose={handleSignUp} openLogin={handleLogin}
/>
<LoginModal open={loginOpen} handleClose={() => setLogin(false)} openSignUp={handleSignUp}
openSnackbar={() => { handleSuccessfulLogin(true) }}
/>
<Snackbar open={successfulLoginOpen} autoHideDuration={1000} onClose={toggleLoginSnackbar}
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
>
<Alert severity="success" style={{ backgroundColor: "#00acc1" }}>Você está conectado(a)!</Alert>
</Snackbar>
<StyledCard>
<CardDiv>
<CardReaDiv>
<Link to={props.href}>
<Header onMouseEnter={controlSlide} onMouseLeave={controlSlide}>
<div className={`slideContentLinkBeforeActive${slideIn}`} style={{ height: '189px' }}>
<img className="img-cover" src={thumbnail} alt="learning object thumbnail" style={{ width: "272.5px" }} />
{
<div className={`slideContentLinkAfterActive${slideIn}`}>
<div className="text" >
{SlideAnimationContent()}
</div>
</div>
}
</Header>
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<Description>
<Link to={props.href} className="text" style={{ height: '45px' }}> {/*add link to learningObject*/}
<Title>
{props.title}
</Title>
</Link>
<Rating
name="customized-empty"
value={props.rating}
readOnly
style={{ color: "#666" }}
emptyIcon={<StarBorderIcon fontSize="inherit" />}
/>
<Footer>
<Type>
{GetIconByName(label)}
<span>{label}</span>
</Type>
<LikeCounter>
<span>{likesCount}</span>
<ButtonNoWidth onClick={handleLike}>
<FavoriteIcon style={{ color: liked ? "red" : "#666" }} />
</ButtonNoWidth>
</LikeCounter>
</Footer>
</Description>
</CardReaDiv>
<CardReaFooter>
<div style={{ display: "flex", height: "100%" }}>
<ButtonGuardarColecao thumb={props.thumbnail} title={props.title} learningObjectId={props.id}
/>
</div>
<ResourceCardOptions
learningObjectId={props.id}
downloadableLink={props.downloadableLink}
thumb={props.thumbnail}
title={props.title}
handleLogin={handleLogin}
</CardReaFooter>
</CardDiv>
</StyledCard>
</React.Fragment>

Lucas Eduardo Schoenfelder
committed
)
}
/*---------- 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
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
`
/*--------------------------------------------*/
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);
`