Opiniones !

This commit is contained in:
Daniel Cortes
2020-07-16 19:23:32 -04:00
parent 502a91328c
commit 713ebfaf46
4 changed files with 35 additions and 24 deletions

View File

@@ -10,6 +10,8 @@ import {Link} from "react-router-dom";
const Opinions = (props) => { const Opinions = (props) => {
const [pressed, setPressed] = useState(null); const [pressed, setPressed] = useState(null);
const user = JSON.parse(window.localStorage.getItem('user'))
let Y = props.helpful.Y; let Y = props.helpful.Y;
let N = props.helpful.N; let N = props.helpful.N;
let F = props.helpful.F; let F = props.helpful.F;
@@ -33,6 +35,8 @@ const Opinions = (props) => {
if (!F) F = ''; if (!F) F = '';
const handleClick = (type) => () => { const handleClick = (type) => () => {
if (user === null) return
if (type === pressed) { if (type === pressed) {
setPressed(null) setPressed(null)
} else { } else {
@@ -86,7 +90,8 @@ const Stars = (props) => {
) )
} }
const Comment = (props) => ( const Comment = (props) => {
return (
<div className='comment'> <div className='comment'>
<div className='avatar'> <div className='avatar'>
<FaUser/> <FaUser/>
@@ -105,6 +110,7 @@ const Comment = (props) => (
</div> </div>
</div> </div>
) )
}
export const Comments = (props) => { export const Comments = (props) => {
const [comments, setComments] = useState(null); const [comments, setComments] = useState(null);
@@ -117,13 +123,18 @@ export const Comments = (props) => {
}) })
} }
if (comments === null) { let comments_component = <h5>No hay comentarios :c</h5>
return null;
}
const comments_component = comments.map((comment, index) => ( if (comments !== null) {
const filtered_comments = comments.filter(comment => comment.opinion);
if (filtered_comments.length !== 0) {
comments_component = comments.map((comment, index) => (
<Comment key={index} user={comment.user} opinion={comment.opinion} stars={comment.stars} helpful={comment.helpful}/> <Comment key={index} user={comment.user} opinion={comment.opinion} stars={comment.stars} helpful={comment.helpful}/>
)); ));
}
}
return ( return (
<div className='comments'> <div className='comments'>

View File

@@ -130,7 +130,7 @@ export const DiscView = (props) => {
onPageChanged={handleVersionPageChanged} makeLink={makeLink} onPageChanged={handleVersionPageChanged} makeLink={makeLink}
navigateToVersion={handleNavigateToVersion}/> navigateToVersion={handleNavigateToVersion}/>
</RowCol> </RowCol>
<RowCol><Comments render={disc}/></RowCol> {disc && <RowCol><Comments entity={mbid}/></RowCol>}
</Grid> </Grid>
) )
} }

View File

@@ -96,7 +96,7 @@ export const ReleaseView = (props) => {
<Grid> <Grid>
<RowCol><Release release={release}/></RowCol> <RowCol><Release release={release}/></RowCol>
<RowCol><Recordings render={release}medias={medias} selected={currentRecording}/></RowCol> <RowCol><Recordings render={release}medias={medias} selected={currentRecording}/></RowCol>
<RowCol><Comments render={release}/></RowCol> {release && <RowCol><Comments entity={mbid}/></RowCol>}
</Grid> </Grid>
) )
} }

View File

@@ -38,7 +38,7 @@ export const SongView = (props) => {
return ( return (
<Grid> <Grid>
<RowCol><Song song={song}/></RowCol> <RowCol><Song song={song}/></RowCol>
<RowCol><Comments render={song}/></RowCol> {song && <RowCol><Comments entity={mbid}/></RowCol>}
</Grid> </Grid>
) )
} }