rating-update-fix
This commit is contained in:
parent
1397cc9b84
commit
f0bddfe461
|
@ -55,27 +55,34 @@ export const RatingControl = (props: RatingControlProps) => {
|
||||||
{ defer: true },
|
{ defer: true },
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
createEffect(
|
||||||
|
on(
|
||||||
|
reactionEntities,
|
||||||
|
() => {
|
||||||
|
const ratings = Object.values(reactionEntities()).filter(r => !r.reply_to);
|
||||||
|
const likes = ratings.filter(rating => rating.kind === 'LIKE').length;
|
||||||
|
const dislikes = ratings.filter(rating => rating.kind === 'DISLIKE').length;
|
||||||
|
const total = likes - dislikes;
|
||||||
|
setTotal(total);
|
||||||
|
},
|
||||||
|
{ defer: true }
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
createEffect(
|
createEffect(
|
||||||
on(
|
on(
|
||||||
[() => props.ratings, author],
|
[() => props.ratings, author],
|
||||||
([reactions, me]) => {
|
([reactions, me]) => {
|
||||||
console.debug('[RatingControl] on reactions update')
|
console.debug('[RatingControl] on reactions update');
|
||||||
const ratingVotes = Object.values(reactions).filter((r) => !r.reply_to)
|
const ratingVotes = Object.values(reactions).filter((r) => !r.reply_to);
|
||||||
setRatings((_) => ratingVotes.sort(byCreated))
|
setRatings((_) => ratingVotes.sort(byCreated));
|
||||||
setMyRate((_) => ratingVotes.find((r) => r.created_by.id === me?.id))
|
setMyRate((_) => ratingVotes.find((r) => r.created_by.id === me?.id));
|
||||||
|
|
||||||
// Extract likes and dislikes from shoutRatings using map
|
|
||||||
const likes = ratingVotes.filter((rating) => rating.kind === 'LIKE').length
|
|
||||||
const dislikes = ratingVotes.filter((rating) => rating.kind === 'DISLIKE').length
|
|
||||||
|
|
||||||
// Calculate the total
|
|
||||||
const total = likes - dislikes
|
|
||||||
setTotal(total)
|
|
||||||
},
|
},
|
||||||
{ defer: true },
|
{ defer: true },
|
||||||
),
|
),
|
||||||
)
|
);
|
||||||
|
|
||||||
|
|
||||||
const handleRatingChange = (voteKind: ReactionKind) => {
|
const handleRatingChange = (voteKind: ReactionKind) => {
|
||||||
requireAuthentication(async () => {
|
requireAuthentication(async () => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user