From c3f0780a5b91748c2894e373eb72ad7791ed2945 Mon Sep 17 00:00:00 2001 From: Daniel Cortes Date: Wed, 15 Jul 2020 00:49:51 -0400 Subject: [PATCH] Implementadas opiniones reales --- src/components/AddToList.jsx | 2 +- src/components/Comments.jsx | 130 ++++++++++++++++++++++++++++------- src/components/Comments.scss | 56 ++++++++++++--- src/services/list_service.js | 4 ++ src/views/Artist.jsx | 2 +- 5 files changed, 155 insertions(+), 39 deletions(-) diff --git a/src/components/AddToList.jsx b/src/components/AddToList.jsx index 02e2870..9aed985 100644 --- a/src/components/AddToList.jsx +++ b/src/components/AddToList.jsx @@ -3,7 +3,7 @@ import Modal from 'react-modal'; import {Button} from './Button'; import './AddToList.scss'; import {useStateValue} from "../services/State"; -import {AiFillStar, AiOutlineStar} from "react-icons/all"; +import {AiFillStar, AiOutlineStar} from "react-icons/ai"; import {add_to_list} from "../services/list_service"; const Star = (props) => { diff --git a/src/components/Comments.jsx b/src/components/Comments.jsx index db06eab..0ae5a24 100644 --- a/src/components/Comments.jsx +++ b/src/components/Comments.jsx @@ -1,52 +1,130 @@ -import React from "react"; -import {FaThumbsUp, FaThumbsDown, FaLaughSquint} from 'react-icons/fa'; +import React, {useState} from "react"; -import Faker from 'faker'; +import {AiFillStar, AiOutlineStar} from "react-icons/ai"; +import {FaUser, FaThumbsUp, FaThumbsDown, FaLaughSquint} from 'react-icons/fa'; import './Comments.scss' +import {get_opinions} from "../services/list_service"; +import {Link} from "react-router-dom"; + +const Opinions = (props) => { + const [pressed, setPressed] = useState(null); + + let Y = props.helpful.Y; + let N = props.helpful.N; + let F = props.helpful.F; + + switch (pressed) { + case 'Y': + Y++; + break; + case 'N': + N++; + break; + case 'F': + F++; + break; + default: + break; + } + + if(!Y) Y = ''; + if(!N) N = ''; + if(!F) F = ''; + + const handleClick = (type) => () => { + if(type === pressed){ + setPressed(null) + }else{ + setPressed(type) + } + }; + + return ( +
+ + + +
+ ) +} + +const Star = (props) => { + return ( +
+ {props.selected ? + : + + } +
+ ) +} + +const Stars = (props) => { + const getSelected = (i) => { + return i <= props.stars + } + + const stars = [ + , + , + , + , + , + ] + + return ( +
+ {stars} +
+ ) +} const Comment = (props) => (
- Avatar +
- {props.user} -

{props.text}

-
- - - + {props.user.username} +

{props.opinion}

+
+ +
) export const Comments = (props) => { - if(!props.render) { + const [comments, setComments] = useState(null); + + if (props.entity !== null && comments === null) { + get_opinions(props.entity).then((response) => { + setComments(response.data.opinions) + }).catch((error) => { + console.log(error) + }) + } + + if (comments === null) { return null; } - let comentarios = []; - - let comment_count = Math.floor(Math.random() * 20) - - for(let i = 0; i < comment_count; i++){ - comentarios.push({ - user: Faker.internet.userName(), - avatar: Faker.internet.avatar(), - text: Faker.lorem.paragraph(20) - }); - } - - comentarios = comentarios.map((comentario, index) => ( - + const comments_component = comments.map((comment, index) => ( + )); return (

Comentarios

- {comentarios} + {comments_component}
) } diff --git a/src/components/Comments.scss b/src/components/Comments.scss index f8bc454..473ba58 100644 --- a/src/components/Comments.scss +++ b/src/components/Comments.scss @@ -11,11 +11,13 @@ height: 75px; margin-right: 1em; outline: 1px var(--gray-2) solid; + background-color: rgb(230, 230, 230); - .avatar { - object-fit: cover; - width: 100%; - height: 100%; + svg { + padding-top: 10%; + width: 90%; + height: 90%; + color: rgb(250, 250, 250); } } @@ -24,18 +26,50 @@ .username { font-weight: 500; } - p { - } } - .buttons { + .acciones { display: flex; flex-direction: row; - button { - border: none; - padding: 0 1em; - background-color: transparent; + &>*{ + margin-right: 1em; + } + + .opinions { + display: flex; + flex-direction: row; + + button { + border: none; + background-color: transparent; + cursor: pointer; + + span > *{ + display: inline; + } + + &:hover, &.selected { + color: var(--accent); + } + + } + } + + .stars { + display: flex; + justify-content: flex-start; + + .star { + margin: inherit; + width: 1.5em; + height: 1.5em; + cursor: auto; + } + + .star.selected { + color: var(--accent); + } } } } diff --git a/src/services/list_service.js b/src/services/list_service.js index 6328ac5..aba6836 100644 --- a/src/services/list_service.js +++ b/src/services/list_service.js @@ -19,3 +19,7 @@ export function add_to_list(token, user_id, entity, entity_type, tags, opinion, headers: {'AUTHORIZATION': `Bearer ${token}`} }); } + +export function get_opinions(mbid) { + return axios.get(`${baseUrl}/entity/${mbid}/opinions`) +} diff --git a/src/views/Artist.jsx b/src/views/Artist.jsx index e79efa5..2f35b89 100644 --- a/src/views/Artist.jsx +++ b/src/views/Artist.jsx @@ -128,7 +128,7 @@ export const ArtistView = (props) => { onPageChanged={handleDiscPageChanged} makeLink={makeLink} navigateToDisc={handleNavigateToDisc}/> - + {artist && } ); }