|
|
@ -1,4 +1,4 @@ |
|
|
|
import React from "react"; |
|
|
|
import React, { useMemo } from "react"; |
|
|
|
import StarRatingComponent from "react-star-rating-component"; |
|
|
|
import StarRatingComponent from "react-star-rating-component"; |
|
|
|
import { userVote, userProduct } from "../../redux/actions"; |
|
|
|
import { userVote, userProduct } from "../../redux/actions"; |
|
|
|
import { connect } from "react-redux"; |
|
|
|
import { connect } from "react-redux"; |
|
|
@ -8,11 +8,18 @@ import location from "../../utils/location"; |
|
|
|
import starGrayIcon from "../../assets/icons/starGray.svg"; |
|
|
|
import starGrayIcon from "../../assets/icons/starGray.svg"; |
|
|
|
import starYellowIcon from "../../assets/icons/starYellow.svg"; |
|
|
|
import starYellowIcon from "../../assets/icons/starYellow.svg"; |
|
|
|
|
|
|
|
|
|
|
|
function StarRating({ value, size, addVote, userProducts, getUserProducts }) { |
|
|
|
function StarRating({ |
|
|
|
|
|
|
|
value, |
|
|
|
|
|
|
|
size, |
|
|
|
|
|
|
|
addVote, |
|
|
|
|
|
|
|
userProducts, |
|
|
|
|
|
|
|
getUserProducts, |
|
|
|
|
|
|
|
isLogin, |
|
|
|
|
|
|
|
}) { |
|
|
|
const [rate, setRating] = React.useState(null); |
|
|
|
const [rate, setRating] = React.useState(null); |
|
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
useMemo(() => { |
|
|
|
getUserProducts(); |
|
|
|
if (isLogin) getUserProducts(); |
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
React.useEffect(() => { |
|
|
@ -55,11 +62,12 @@ function StarRating({ value, size, addVote, userProducts, getUserProducts }) { |
|
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({ |
|
|
|
const mapStateToProps = (state) => ({ |
|
|
|
userProducts: state.userProduct.list, |
|
|
|
userProducts: state.userProduct.list, |
|
|
|
|
|
|
|
isLogin: state.user.status, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = { |
|
|
|
const mapDispatchToProps = { |
|
|
|
addVote: userVote.add, |
|
|
|
addVote: userVote.add, |
|
|
|
getUserProducts: userProduct.list, |
|
|
|
getUserProducts: userProduct.list || [], |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(StarRating); |
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(StarRating); |
|
|
|