Newer
Older
/*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, { useContext, useState, useEffect } from 'react';
import { Grid } from '@material-ui/core';
import Rating from '@material-ui/lab/Rating';
import IconButton from '@material-ui/core/IconButton';
import StarBorderIcon from '@material-ui/icons/StarBorder';
import FavoriteIcon from '@material-ui/icons/Favorite';
import InfoIcon from '@material-ui/icons/Info';
import SignUpModal from './SignUpModal.js';
import LoginModal from './LoginModal.js';
import { putRequest } from './HelperFunctions/getAxiosConfig.js'
import SnackBarComponent from './SnackbarComponent';
const { state } = useContext(Store);
const [likes, setLikes] = useState();
const [liked, setLiked] = useState();
const [stars, setStars] = useState();
const [sign_up_open, setSignUpOpen] = useState(false);
const [log_in_open, setLoginOpen] = useState(false);
const [snackInfo, setSnackInfo] = useState({
open: false,
text: '',
severity: '',
color: ''
});
if (state.currentUser.id)
setReportOpen(true);
else
setSignUpOpen(true)
function handleSuccess(data) {
setLiked(!liked)
setLikes(data.count)
}
const url = `/collections/${props.id}/like`
putRequest(url, {}, handleSuccess, (error) => { console.log(error) })
}
const handleCloseModal = () => {
setReportOpen(false);
}
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function handleOpenSnackSignIn() {
const info = {
open: true,
text: 'Você foi logado com sucesso!',
severity: 'success',
color: '',
}
handleSnackInfo(info)
}
function handleSnackInfo(info) {
setSnackInfo({
...info
})
}
function handleCloseSnack() {
setSnackInfo({
open: false,
text: '',
severity: '',
color: '',
})
}
function handleOpenSignUp() {
setSignUpOpen(true)
}
useEffect(() => {
setLiked(props.liked)
setLikes(props.likes)
setStars(props.stars)
}, [props])
<Grid container direction="column" style={props.contrast === "" ? {color: "#666"} : {color: "white"}}>
<SnackBarComponent
snackbarOpen={snackInfo.open}
handleClose={handleCloseSnack}
severity={snackInfo.severity}
text={snackInfo.text}
color={snackInfo.color}
/>
<Grid sm={12} container direction="row" alignItems="center"
style={{justifyContent: "center"}}
>
<Grid item>
<Rating
style={props.contrast === "" ? {} : {color: "white"}}
name="customized-empty"
value={Number(stars)}
readOnly
onClick={props.scrollToComment}
emptyIcon={<StarBorderIcon className={`${props.contrast}Text`} fontSize="inherit" />}
/>
</Grid>
<Grid item justify="center" alignItems="center">
<IconButton style={{color: "inherit"}} aria-label="like" onClick={handleLikeClick}>
{likes}<FavoriteIcon style={props.contrast === "" ? {fill: liked ? "red" : null} : {fill: "yellow"}} />
</IconButton>
</Grid>
<IconButton
aria-label="report"
<InfoIcon style={props.contrast === "" ? {color: "#666"} : {color: "white"}}/><span style={props.contrast === "" ? {color: "#666"} : {color: "yellow", textDecoration: "underline"}}>Reportar erro ou abuso</span>
open={reportOpen}
handleClose={handleCloseModal}
form="colecao"
complainableId={props.id}
complainableType="Collection"
/>
open={sign_up_open}
handleClose={() => setSignUpOpen(false)}
openLogin={() => setLoginOpen(true)}
/>
<LoginModal
open={log_in_open}
handleClose={() => setLoginOpen(false)}