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,25 +90,27 @@ const Stars = (props) => {
) )
} }
const Comment = (props) => ( const Comment = (props) => {
<div className='comment'> return (
<div className='avatar'> <div className='comment'>
<FaUser/> <div className='avatar'>
</div> <FaUser/>
<div className='content'>
<div className="header">
<Link to={`/user/${props.user.id}`} className='username'>{props.user.username}</Link>
<Stars stars={props.stars}/>
</div> </div>
<div className="body"> <div className='content'>
<p>{props.opinion}</p> <div className="header">
</div> <Link to={`/user/${props.user.id}`} className='username'>{props.user.username}</Link>
<div className="footer"> <Stars stars={props.stars}/>
<Opinions helpful={props.helpful}/> </div>
<div className="body">
<p>{props.opinion}</p>
</div>
<div className="footer">
<Opinions helpful={props.helpful}/>
</div>
</div> </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;
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}/>
));
}
} }
const comments_component = comments.map((comment, index) => (
<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>
) )
} }