Skip to content

Commit

Permalink
Fix first rating issue (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
onemen committed Mar 24, 2020
1 parent 0fd5e8e commit a3d6050
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as colors from '../styles/colors'

function Rating({listItem}) {
const [isTabbing, setIsTabbing] = React.useState(false)
const [rating, setRating] = React.useState(listItem.rating)

const [mutate, {error}] = useUpdateListItem(listItem)

Expand Down Expand Up @@ -40,8 +41,11 @@ function Rating({listItem}) {
type="radio"
id={ratingId}
value={ratingValue}
defaultChecked={ratingValue === listItem.rating}
onChange={() => debouncedMutate({rating: ratingValue})}
defaultChecked={ratingValue === rating}
onChange={() => {
setRating(ratingValue)
debouncedMutate({rating: ratingValue})
}}
className="visually-hidden"
css={{
[`.${rootClassName} &:checked ~ label`]: {color: colors.gray20},
Expand All @@ -67,7 +71,7 @@ function Rating({listItem}) {
htmlFor={ratingId}
css={{
cursor: 'pointer',
color: listItem.rating < 0 ? colors.gray20 : 'orange',
color: rating < 0 ? colors.gray20 : 'orange',
margin: 0,
}}
>
Expand Down

0 comments on commit a3d6050

Please sign in to comment.