Skip to content
Snippets Groups Projects
Commit 196d7dac authored by Raul Almeida's avatar Raul Almeida
Browse files

WIP Collection Page

parent db88fb37
No related branches found
No related tags found
5 merge requests!57Merge of develop into master,!56Fixed buttons reportar, seguir, compartilhar, guardar and entrar (in comments...,!39Update admin system,!32Homologa,!23Tela de coleção
...@@ -54,7 +54,7 @@ export default function CollectionDescription(props) { ...@@ -54,7 +54,7 @@ export default function CollectionDescription(props) {
</DownloadButton> </DownloadButton>
</Grid> </Grid>
<Grid item> <Grid item>
<FollowCollectionButton user_id={state.currentUser.id}/> <FollowCollectionButton user_id={state.currentUser.id} collection_id={props.collection_id}/>
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>
...@@ -73,7 +73,7 @@ const ButtonText=styled.span` ...@@ -73,7 +73,7 @@ const ButtonText=styled.span`
font-size: 1.2em; font-size: 1.2em;
` `
const DownloadButton=styled(Button)` const DownloadButton=styled(Button)`
padding-left: 10, padding-left: 10;
padding-right: 10, padding-right: 10;
width: 210, width: 250px;
` `
...@@ -16,33 +16,70 @@ GNU Affero General Public License for more details. ...@@ -16,33 +16,70 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License 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/>.*/ along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import Button from '@material-ui/core/Button'; import Button from '@material-ui/core/Button';
import CheckIcon from '@material-ui/icons/Check'; import CheckIcon from '@material-ui/icons/Check';
import AddIcon from '@material-ui/icons/Add'; import AddIcon from '@material-ui/icons/Add';
import styled from 'styled-components'; import styled from 'styled-components';
import SignUpModal from './SignUpModal.js'; import SignUpModal from './SignUpModal.js';
import axios from 'axios';
import {apiUrl} from '../env';
export default function FollowCollectionButton(props) { export default function FollowCollectionButton(props) {
const [icon, setIcon] = useState(<AddIcon fontSize="large"/>); const [icon, setIcon] = useState(<AddIcon fontSize="large"/>);
const [button_text, setButtonText] = useState("Seguir Coleção"); const [button_text, setButtonText] = useState("Seguir Coleção");
const [variant, setVariant] = useState("outlined"); const [variant, setVariant] = useState("outlined");
const [sign_up_open, setSignUpOpen] = useState(false); const [sign_up_open, setSignUpOpen] = useState(false);
const [following, setFollowing] = useState(false); //user following collection
const handleClick = () => { useEffect(() => {
//aqui tem que ter: axios.get(apiUrl+'/users/'+props.user_id+'/following/Collection')
//se o usuário não está logado, abre a tela de criar conta .then(res => {
for (const element in res.body)
//setSignUpOpen(true); if (element.id == props.collection_id)
setFollowing(true);
});
}, [])
//se o usuário já segue a coleção,deixa de seguir //handleMouse{Enter, Leave} only do anything when user follows given collection:
const handleMouseEnter = () => {
if (following) {
setVariant("outlined");
setButtonText("Deixar de seguir");
setIcon(null);
}
}
const handleMouseLeave = () => {
if (following) {
setVariant("contained");
setButtonText("Seguindo");
setIcon(<CheckIcon fontSize="large" />);
}
}
//setButtonText("Seguir Coleção"); const handleClick = () => {
if (!props.user_id)
//se o usuário não segue a coleção, muda o visual por alguns instantes e depois mostra o "deixa de seguir" setSignUpOpen(true);
setVariant("contained"); else if (!following) {
setButtonText("Seguindo"); setVariant("contained");
setIcon(<CheckIcon fontSize="large"/>) setButtonText("Seguindo");
setIcon(<CheckIcon fontSize="large"/>)
axios.post(apiUrl+'/Collection/'+props.collection_id+'/follow')
.then(res => {
if (Number(res.status) == 201)
setFollowing(true);
});
} else {
setVariant("outlined");
setButtonText("Deixar de seguir");
setIcon(<AddIcon fontSize="large"/>);
axios.delete(apiUrl+'/Collection/'+props.collection_id+'/follow')
.then(res => {
if (Number(res.status) == 200)
setFollowing(false);
});
}
}; };
return ( return (
...@@ -52,7 +89,9 @@ export default function FollowCollectionButton(props) { ...@@ -52,7 +89,9 @@ export default function FollowCollectionButton(props) {
color="primary" color="primary"
startIcon={icon} startIcon={icon}
size="large" size="large"
onClick={() => handleClick()} onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onClick={handleClick}
> >
<ButtonText>{button_text}</ButtonText> <ButtonText>{button_text}</ButtonText>
</FollowButton> </FollowButton>
...@@ -71,7 +110,7 @@ const ButtonText=styled.span` ...@@ -71,7 +110,7 @@ const ButtonText=styled.span`
font-size: 1.2em; font-size: 1.2em;
` `
const FollowButton=styled(Button)` const FollowButton=styled(Button)`
padding-left: 10, padding-left: 10;
padding-right: 10, padding-right: 10;
width: 210, width: 250px;
` `
...@@ -39,7 +39,7 @@ export default function CollectionPage() { ...@@ -39,7 +39,7 @@ export default function CollectionPage() {
<VerticalRuler width={1} height={300} color="rgb(238, 238, 238)"/> <VerticalRuler width={1} height={300} color="rgb(238, 238, 238)"/>
<Grid item xs={10} md={6}> <Grid item xs={10} md={6}>
<CollectionDescription title="Linguagem de Programacao"/> <CollectionDescription title="Linguagem de Programacao" collection_id="9868"/>
</Grid> </Grid>
<Grid container item direction="row" justify="center" alignItems="center" style={{backgroundColor: '#f4f4f4'}}> <Grid container item direction="row" justify="center" alignItems="center" style={{backgroundColor: '#f4f4f4'}}>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment